/********************************一些公用方法*********************************/
function $() {return document.getElementById(arguments[0]);};
function $C() {return document.createElement(arguments[0]);};
function $click(obj){if(obj == null){return;}else{if(document.uniqueID){obj.click();}else{var mEv = document.createEvent('MouseEvents');mEv.initEvent('click',true,true);obj.dispatchEvent(mEv);}}};
function $gstyle(obj){if(document.uniqueID){return obj.style.cssText;}else{return obj.getAttribute("style");}};
function $sstyle(obj,code){if(document.uniqueID){obj.style.cssText = code;}else{obj.setAttribute("style",code);}};
/**
 * @author wangdonghao
 */
/************************************Tree类**************************************/
    
    function Tree(treedivid){//start Tree主类
        /***私有变量***/
        var treeDivId = treedivid;                                             //树形所在的div的id
        var treeDiv = null;                                                    //树形所在的div
        var menuDivId = treeDivId+"_Menu";                                      //一级菜单的div的id
        var subMenuDivId = treeDivId+"_SubMenu";                                //下级菜单的div的id
        
        var selectedNode = null;                                               //当前被选择的节点行
        var lastSelectedNode = null;                                           //上一次被选择的节点行
        var parentLoadNode = null;                                             //要去加载子节点的行
        
        var ctrlKey = false;                                                   //是否按下了ctrl键
        var shiftKey = false;                                                  //是否按下了shift键
        /***外部可以访问的变量***/
        this.readyState = "init";                                              //树形展开节点时的状态，五个状态 begin(函数开始执行,这个是后来加的), loading(加载数据),loaded(数据加载完),interactive(交互，执行回调函数),complete(展开结束)
        
        //Ajax相关属性
        var xmlHttpRequest = null;                                             //XMLHttpRequest实例
        var isDownLoading = false;                                             //是否正在下载节点 
        var queryString = null;                                                //提交的查询相关的request参数
        var returnJson = null;                                                 //服务器端返回的Json
        var loader = this;                                                     //当向与onreadystatechange绑定的函数传this时调用
        this.serverUrl = null;                                                 //server页面的URL
        
        //表格相关属性
        var treeTable = null;                                                  //整个控件的table
        var treeTbody = null;                                                  //table中的tbody，主要是在IE中使用
        var treeCell = null;                                                   //table中树形的单元格
        var extendCell = null;                                                 //扩展列的单元格
        var headCell = null;                                                   //table中的表头行中的单元格
        var treeLabel = null;                                                  //包围节点文字的label
        var treeCheckbox = null;                                               //控件中的checkbox
       
        //图标相关属性
        var nodeIcon = null;                                                   //“节点”图标
        var openNode = null;                                                   //“打开的节点”图标
        var leafNodeIcon = null;                                               //“叶子节点”图标
        var selectedNodeIcon = null;                                           //“被选择节点”
        var waitingImg = null;                                                 //“等待”图标
        var lineIcon1 = null;                                                  //“下、右连接线”图标
        var lineIcon2 = null;                                                  //“上、右、下连接线”图标
        var lineIcon3 = null;                                                  //“上、右连接线”图标
        var lineIcon4 = null;                                                  //“上、下连接线”图标
        var plusIcon1 = null;                                                  //“加号”图标（有右连接线）
        var plusIcon2 = null;                                                  //“加号”图标（有右、下连接线）
        var plusIcon3 = null;                                                  //“加号”图标（有右、上、下连接线）
        var plusIcon4 = null;                                                  //“加号”图标（有右、上连接线）
        var subIcon1 = null;                                                   //“减号”图标（有右连接线）
        var subIcon2 = null;                                                   //“减号”图标（有右、下连接线）
        var subIcon3 = null;                                                   //“减号”图标（有右、上、下连接线）
        var subIcon4 = null;                                                   //“减号”图标（有右、上连接线）
        var emptyIcon = null;                                                  //”空白“图标
        var backgroundIcon = null;                                             //“树的背景”图标
        var imgTemp = null;                                                    //一个图片的备份，加了一些公有属性，供别的图片克隆
        
        
        //菜单和子菜单的div
        var menuDiv = null;                                                    //菜单div
        var subMenuDiv = null;                                                 //子菜单div
        
        var menuFirst = new Menu(this);                                        //一级菜单，Menu实例
        
        //绑定事件
        var events = [];                                                       //事件名称为key，相应的自定义函数名为value

        //搜索相关
        var searchResult = new SearchResult();                                 //搜索结果的实例
        
        //一些公共变量
        var checkedBoxes = null;                                               //当前被checked的checkbox
        var deletedRow = null;                                                 //要删除的节点
        var insertNodeId = null;                                               //记录插入节点的id
        var selectedNodeStyle = null;                                          //当前被选择节点在被选择前的样式代码
        var refresh = null;                                                    //当前是否进行了刷新操作，1为刷新了子节点列表，2为刷新当前节点列表
        var refreshRowId = null;                                               //记录刷新前选择的节点行的id
        var refreshRowIndex = null;                                            //记录刷新前选择的节点的行号
        var shiftCtrlChecked = null;                                          //当按shift或ctrl点checkbox时，如果展开所有下级或直接，则记住该checkbox状态

        /***公有变量***/
        this.webTreeIntfInstId = null;                                         //当前树形对应的的WebTreeIntf接口的实例id
        
        this.isAutoToFirstNode = true;                                         //初始化时是否自动定位到第一个节点
        this.isAutoToFirstLeafNode = false;                                    //初始化树时是否自动定位到第一个叶子节点
        this.maxDeep = 10;                                                     //自动定位到第一个叶子节点时寻找的最大深度,默认为10层
        this.isShowCheckbox = false;                                           //树中是否显示checkbox
        this.isShowMenu = false;                                               //是否可以显示右键菜单
        this.isCollapseOtherNodes = false;                                     //整棵树点击当前节点的时候是否使其同级节点折叠起来
        this.isShiftLoadAllChildren = false;                                   //按住shift键点击某个节点,是否把该节点的所有子节点全部加载下来
        this.isCtrlLoadAllDirChildren = false;                                 //按住ctrl键点击某个节点,是否把该节点的所有直接子节点全部加载下来（不分页）
        this.extendColCount = 0;                                               //扩展列的列数,默认为0，即没有扩展列
        this.extendColsTitles = new Array();                                   //所有扩展列的标题的列表
        
        this.treeStyleDocPath = null;                                          //树形样式单的路径
        this.styleCode = null;                                                 //树的表格的样式代码
        this.headStyleCode = null;                                             //表头行的样式代码
        this.treeStyleCode = null;                                             //控件中的树单元格的样式代码
        this.extendStyleCode = null;                                           //扩展列单元格样式代码
        this.nodeStyleCode = null;                                             //节点样式代码
        this.selectedNodeStyleCode = "background-color:#a3d4ff";               //被选择的节点的样式代码
        this.menuStyleCode = null;                                             //菜单的样式代码
        
        this.iconsDirectory = null;                                            //树形的图片的统一目录路径
        this.nodesIconPath = null;                                             //“节点”图标的统一路径
        this.openNodesPath = null;                                             //“打开的节点”图标的路径
        this.leafNodesPath = null;                                             //“叶子节点”图标的路径
        this.selectedNodesPath = null;                                         //“被选择节点”的路径
        this.waitingImgName = null;                                            //“等待”图标的文件名
        this.lineIcon1Name = null;                                             //“下、右连接线”图标文件名
        this.lineIcon2Name = null;                                             //“上、右、下连接线”图标文件名
        this.lineIcon3Name = null;                                             //“上、右连接线”图标文件名
        this.lineIcon4Name = null;                                             //“上、下连接线”图标文件名
        this.plusIcon1Name = null;                                             //“加号”图标（有右连接线）文件名
        this.plusIcon2Name = null;                                             //“加号”图标（有右、下连接线）文件名
        this.plusIcon3Name = null;                                             //“加号”图标（有右、上、下连接线）文件名
        this.plusIcon4Name = null;                                             //“加号”图标（有右、上连接线）文件名
        this.subIcon1Name = null;                                              //“减号”图标（有右连接线）文件名
        this.subIcon2Name = null;                                              //“减号”图标（有右、下连接线）文件名
        this.subIcon3Name = null;                                              //“减号”图标（有右、上、下连接线）文件名
        this.subIcon4Name = null;                                              //“减号”图标（有右、上连接线）文件名
        this.emptyIconName = null;                                             //空白图片文件名
        this.backgroundIconName = null;                                        //“树的背景”图标文件名
        
        this.imgWidth = 18;                                                    //图片宽度
        this.imgHeight = 18;                                                   //图片高度
        this.checkWidth = 18;                                                  //checkbox宽度
        this.checkHeight = 18;                                                 //checkbox高度
        
        /***函数部分***/
        
        /**
          * 如果允许右键菜单，则初始化菜单相关内容
          */
        var initMenu = function(){
            if(treeDiv == null || !this.isShowMenu){  //不允许右键菜单
                return null;
            }
            menuDiv = $C("div");
            subMenuDiv = $C("div");
            document.body.appendChild(menuDiv);
            document.body.appendChild(subMenuDiv);
            menuDiv.setAttribute("id",menuDivId);
            subMenuDiv.setAttribute("id",subMenuDivId);
            menuDiv.style.display = "none";
            subMenuDiv.style.display = "none";
            var menuDivIds = new Array();
            menuDivIds.push(menuDivId,subMenuDivId);
            menuFirst.setMenuDivIds(menuDivIds);
            menuFirst.setLayer(1);
            if(this.iconsDirectory != null && this.iconsDirectory != ""){  //设置菜单图标的路径
                menuFirst.iconsDirectory = this.iconsDirectory;
            }
            if(this.menuStyleCode != null && this.menuStyleCode != ""){  //设置菜单整体表格的样式代码
                menuFirst.menuStyleCode = this.menuStyleCode;
            }    
			menuFirst.init();
        };//end initMenu
        
        
        /**
          * 初始化table相关内容
          */
        var initTable = function(){
            treeTable = $C("table");
            treeTbody = $C("tbody");
            treeRow = $C("tr");
            headRow = $C("tr");
            treeCell = $C("td");
            extendCell = $C("td");
            headCell = $C("td");
            treeLabel = $C("label");
            treeCheckbox = $C("input");
            
            treeCheckbox.setAttribute("type","checkbox");
            treeCheckbox.style.width = this.checkWidth;
            treeCheckbox.style.height = this.checkHeight;
            treeCheckbox.setAttribute("style","width:"+this.checkWidth+"px;height:"+this.checkHeight+"px;");
            
            //下面这些都是设置style，完全可以在样式单里设置
            $sstyle(treeCell,"white-space :nowrap");  //单元格中不回车换行
            $sstyle(extendCell,"white-space :nowrap");
            $sstyle(headCell,"white-space :nowrap");
            
            //这里应该设置css的class属性
            var strClass;
            if(document.uniqueID){strClass = "className";}else{strClass = "class";}
            treeTable.setAttribute(strClass,"WebTreeTable");
            treeCell.setAttribute(strClass,"WebTreeCell");
            extendCell.setAttribute(strClass,"WebTreeExtendCell");  
            headCell.setAttribute(strClass,"WebTreeHeadCell");
            treeLabel.setAttribute(strClass,"WebTreeCellLabel");
            
            //这里设置单独的样式代码
            if(this.styleCode != null){
                $sstyle(treeTable,$gstyle(treeTable) + ";" + this.styleCode);
            }
            if(this.headStyleCode != null){
                $sstyle(headCell,$gstyle(headCell) + ";" + this.headStyleCode);
            }
            if(this.treeStyleCode != null){
                $sstyle(treeCell,$gstyle(treeCell) + ";" + this.treeCell);
            }
            if(this.extendStyleCode != null){
                $sstyle(extendCell,$gstyle(extendCell) + ";" + this.extendCell);
            }
            if(this.nodeStyleCode != null){
                $sstyle(treeLabel,$gstyle(treeLabel) + ";" + this.nodeStyleCode);
            }
        
        };//end initTable
          
        /**
          * 初始化图标相关内容
          */    
        var initIcon = function(){
            if(this.iconsDirectory != null && this.iconsDirectory != ""){
                imgTemp            = $C("img");
                imgTemp.align          = "absmiddle"; //整体设置公有属性
                imgTemp.style.width = this.imgWidth;
                imgTemp.style.height = this.imgHeight;
                
                var folderTemp = imgTemp.cloneNode(true);
                var expandTemp = imgTemp.cloneNode(true);
                folderTemp.setAttribute("flag",2);
                expandTemp.setAttribute("flag",1);
                
                
                nodeIcon           = folderTemp.cloneNode(true);
                openNode           = folderTemp.cloneNode(true);
                leafNodeIcon       = folderTemp.cloneNode(true);
                selectedNodeIcon   = folderTemp.cloneNode(true);
                waitingImg         = $C("img");
                lineIcon1          = imgTemp.cloneNode(true);
                lineIcon2          = imgTemp.cloneNode(true);
                lineIcon3          = imgTemp.cloneNode(true);
				lineIcon4          = imgTemp.cloneNode(true);
                plusIcon1          = expandTemp.cloneNode(true);
                plusIcon2          = expandTemp.cloneNode(true);
                plusIcon3          = expandTemp.cloneNode(true);
                plusIcon4          = expandTemp.cloneNode(true);
                subIcon1           = expandTemp.cloneNode(true);
                subIcon2           = expandTemp.cloneNode(true);
                subIcon3           = expandTemp.cloneNode(true);
                subIcon4           = expandTemp.cloneNode(true);
                emptyIcon          = imgTemp.cloneNode(true);
                backgroundIcon     = $C("img");
                
                if(this.nodesIconPath == null){
                    nodeIcon.setAttribute("src",this.iconsDirectory+"folder.gif");
                }else{
                    nodeIcon.setAttribute("src",this.nodesIconPath);
                }
                
                if(this.openNodesPath == null){
                    openNode.setAttribute("src",this.iconsDirectory+"openfolder.gif");
                }else{
                    openNode.setAttribute("src",this.openNodesPath);
                }
                
                if(this.leafNodesPath == null){
                    leafNodeIcon.setAttribute("src",this.iconsDirectory+"leaf.gif");
                }else{
                    leafNodeIcon.setAttribute("src",this.leafNodesPath);
                }
                
                if(this.selectedNodesPath == null){
                    selectedNodeIcon.setAttribute("src",this.iconsDirectory+"selected.gif");
                }else{
                    selectedNodeIcon.setAttribute("src",this.selectedNodesPath);
                }
                
                if(this.waitingImgName == null){
                    waitingImg.setAttribute("src",this.iconsDirectory+"clock_new.gif");
                }else{
                    waitingImg.setAttribute("src",this.iconsDirectory+this.waitingImgName);
                }
                
                if(this.lineIcon1Name == null){
                    lineIcon1.setAttribute("src",this.iconsDirectory+"line1.gif");
                }else{
                    lineIcon1.setAttribute("src",this.iconsDirectory+this.lineIcon1Name);
                }
                
                if(this.lineIcon2Name == null){
                    lineIcon2.setAttribute("src",this.iconsDirectory+"line2.gif");
                }else{
                    lineIcon2.setAttribute("src",this.iconsDirectory+this.lineIcon2Name);
                }
                
                if(this.lineIcon3Name == null){
                    lineIcon3.setAttribute("src",this.iconsDirectory+"line3.gif");
                }else{
                    lineIcon3.setAttribute("src",this.iconsDirectory+this.lineIcon3Name);
                }
				
				if(this.lineIcon4Name == null){
                    lineIcon4.setAttribute("src",this.iconsDirectory+"line4.gif");
                }else{
                    lineIcon4.setAttribute("src",this.iconsDirectory+this.lineIcon4Name);
                }
                
                if(this.plusIcon1Name == null){
                    plusIcon1.setAttribute("src",this.iconsDirectory+"plus1.gif");
                }else{
                    plusIcon1.setAttribute("src",this.iconsDirectory+this.plusIcon1Name);
                }
                
                if(this.plusIcon2Name == null){
                    plusIcon2.setAttribute("src",this.iconsDirectory+"plus2.gif");
                }else{
                    plusIcon2.setAttribute("src",this.iconsDirectory+this.plusIcon2Name);
                }
                
                if(this.plusIcon3Name == null){
                    plusIcon3.setAttribute("src",this.iconsDirectory+"plus3.gif");
                }else{
                    plusIcon3.setAttribute("src",this.iconsDirectory+this.plusIcon3Name);
                }
                
                if(this.plusIcon4Name == null){
                    plusIcon4.setAttribute("src",this.iconsDirectory+"plus4.gif");
                }else{
                    plusIcon4.setAttribute("src",this.iconsDirectory+this.plusIcon4Name);
                }
                
                if(this.subIcon1Name == null){
                    subIcon1.setAttribute("src",this.iconsDirectory+"sub1.gif");
                }else{
                    subIcon1.setAttribute("src",this.iconsDirectory+this.subIcon1Name);
                }
                
                if(this.subIcon2Name == null){
                    subIcon2.setAttribute("src",this.iconsDirectory+"sub2.gif");
                }else{
                    subIcon2.setAttribute("src",this.iconsDirectory+this.subIcon2Name);
                }
                
                if(this.subIcon3Name == null){
                    subIcon3.setAttribute("src",this.iconsDirectory+"sub3.gif");
                }else{
                    subIcon3.setAttribute("src",this.iconsDirectory+this.subIcon3Name);
                }
                
                if(this.subIcon4Name == null){
                    subIcon4.setAttribute("src",this.iconsDirectory+"sub4.gif");
                }else{
                    subIcon4.setAttribute("src",this.iconsDirectory+this.subIcon4Name);
                }
                
                if(this.backgroundIconName == null){
                    backgroundIcon.setAttribute("src",this.iconsDirectory+"bg.gif");
                }else{
                    backgroundIcon.setAttribute("src",this.iconsDirectory+this.backgroundIconName);
                }
                
                if(this.emptyIconName == null){
                    emptyIcon.setAttribute("src",this.iconsDirectory+"emptyicon.gif");
                }else{
                    emptyIcon.setAttribute("src",this.iconsDirectory+this.emptyIconName);
                }
                //emptyIcon.setAttribute("flag",2);
            }
        };//end intiIcon
        
        /**
          *设置等待图片的位置，由于图片在加入document之前是得不到宽度和长度的，所以，这个函数必须在加入document后调用
          */
        var setWaitingImgPosition = function(){
             var num1 = treeDiv.clientWidth/2-waitingImg.clientWidth/2 + treeDiv.scrollLeft;
             var num2 = treeDiv.clientHeight/2-waitingImg.clientHeight/2 +treeDiv.scrollTop;
             if(num1 < 0 ) num1 = 0;
             if(num2 < 0) num2 = 0;
            var styleCode = "position:absolute;z-index:190;left:"+num1+";bottom:"+num2+";";
            waitingImg.style.cssText = styleCode;
            waitingImg.setAttribute("style",styleCode);
        };
        
        /**
          *为对象中的表格、图标、菜单div等属性初始化
          */
        this.init = function(){
            treeDiv = $(treeDivId);
            if(treeDiv == null) return null;
            initMenu.call(loader);  //菜单相关
            initTable.call(loader); //表格相关
            initIcon.call(loader);  //图标相关
            treeDiv.style.backgroundImage = "url("+backgroundIcon.getAttribute("src")+")";
        };//end init
        
        
        /**
          *开始生成树
          */
        this.createTree = function(){//alert("test");
            this.init();  //初始化表格、图标、菜单div等对象
            
            if(treeDivId == null){  //测试树的容器是否存在
                alert("树的容器对象不存在！");
                return;
            }else if(treeDiv == null){
                alert("Id为【"+treeDivId+"】的树容器不存在！");
                return;
            }
            
            if(this.isShowMenu){  //点击时隐藏菜单
                treeDiv.onclick = function(){
                    if(menuFirst != null){
                        menuFirst.hideMenu();
                    }
                };
            }
            
            
            //生成控件中的表格关系
            var headRow = $C("tr");
            treeDiv.appendChild(treeTable);
            treeDiv.appendChild(waitingImg);  //将等待图片加入div中
            setWaitingImgPosition.call(loader);  //设置等待图片位置
            treeTable.appendChild(treeTbody);  //IE中table加行必须加到tbody上
            treeTbody.appendChild(headRow);
            //生成表头行
            treeTable.oncontextmenu = function(){return false;};
            headRow.oncontextmenu = function(){return false;};  //屏蔽右键
            for(var i=-1;i<this.extendColCount&&i<this.extendColsTitles.length;i++){
                var cell = headCell.cloneNode(true);
                headRow.appendChild(cell);
                var textNode = document.createTextNode(" ");
                cell.appendChild(textNode);
                if(i > -1){
                    textNode.data = this.extendColsTitles[i];
                }
            }
            if(this.extendColCount == 0){  //如果没有扩展列，则隐藏表头行
                headRow.style.display = "none";
            }
            this.dealRequest(1,"");  //得到根节点//本来是以div标识作为虚拟根节点的标识的，现在改为空字符串
        };//end createTree
        
        /**
          *根据flag的值来处理请求
          */
        this.dealRequest = function(flag,id){
            if(this.readyState == "loading"){  //如果有节点正在加载，则停止该函数
                //alert("节点正在下载！");
                return;
            }
            
            waitingImg.style.display = "";
            
            var queryArray = null;  //用于生成request参数的数组
            var dealType = null;  //服务器端的操作标志
            var nodeId = null;  //节点标识
            var webTreeIntfInstId = null;  //用户定义的WebTreeIntf的接口实例的标识
            var next = null;  //是否为分页节点
            var pageNum = 1;  //页码
            var ctrl = null;  //是否按住ctrl键
            var shift = null;  //是否按住shift键
            
            if(id == null){
                return;
            }else{
                xmlHttpRequest = this.createXMLHttpRequest();
                if(xmlHttpRequest == null){
                    alert("您的浏览器不支持XMLHttpRequest!");
                    return;
                }
                
                if(flag == 1){  //初始化树，取根节点
                    queryArray = new Array();
                    dealType = new Array("dealType","1");
                    nodeId = new Array("nodeId",id);
                    webTreeIntfInstId = new Array("webTreeIntfInstId",this.webTreeIntfInstId);
                    if(ctrlKey){
                        ctrl = new Array("ctrlKey","1");
                        ctrlKey = false;
                    }
                    if(shiftKey){
                        shift = new Array("shiftKey","1");
                        shiftKey = false;
                    }
                    var shiftLoadAllChildren = null;
                    if(this.isShiftLoadAllChildren){
                         shiftLoadAllChildren = new Array("shiftChildren","1");
                    }
                    var ctrlLoadAllDirChildren = null;
                    if(this.isCtrlLoadAllDirChildren){
                        ctrlLoadAllDirChildren = new Array("ctrlChildren","1");
                    }
                    var checkboxState = null;
                    if(shiftCtrlChecked != null){
                        checkboxState = new Array("checkboxState",shiftCtrlChecked);
                        shiftCtrlChecked = null;
                    }
                    
                    queryArray.push(dealType,nodeId,webTreeIntfInstId,pageNum,ctrl,shift,ctrlLoadAllDirChildren,shiftLoadAllChildren,checkboxState);
                    queryString = this.createQueryString(queryArray);

                    this.doRequestUsingPost.call(loader,1,id);  //开始加载节点数据
                    
                }else if(flag == 2){
                    var rowObj = $(nodeToRowId(id));
                    var rowId = null;
                    if(rowObj != null){
                        if(rowObj.getAttribute("next") == "1"){  //分页节点
                          pageNum = new Array("pageNum",rowObj.getAttribute("pNum"));
                          rowId = rowObj.getAttribute("parent");
                        }else{
                            rowId = id;
                        }
                        
                        queryArray = new Array();
                        dealType = new Array("dealType","1");
                        nodeId = new Array("nodeId",rowId);
                        webTreeIntfInstId = new Array("webTreeIntfInstId",this.webTreeIntfInstId);
                        
                        var ctrl = null;
                        var shift = null;
                        if(ctrlKey){
                            ctrl = new Array("ctrlKey","1");
                            ctrlKey = false;
                        }
                        if(shiftKey){
                            shift = new Array("shiftKey","1");
                            shiftKey = false;
                        }
                        var shiftLoadAllChildren = null;
                        if(this.isShiftLoadAllChildren){
                            shiftLoadAllChildren = new Array("shiftChildren","1");
                        }
                        var ctrlLoadAllDirChildren = null;
	                    if(this.isCtrlLoadAllDirChildren){
	                        ctrlLoadAllDirChildren = new Array("ctrlChildren","1");
	                    }
	                    var checkboxState = null;
	                    if(shiftCtrlChecked != null){
	                        checkboxState = new Array("checkboxState",shiftCtrlChecked);
	                        shiftCtrlChecked = null;
	                    }
                        queryArray.push(dealType,nodeId,webTreeIntfInstId,pageNum,ctrl,shift,ctrlLoadAllDirChildren,shiftLoadAllChildren,checkboxState);
                        queryString = this.createQueryString(queryArray);
                        
                        this.doRequestUsingPost.call(loader,2,id);  //开始加载节点数据
                        
                    }else{
                        waitingImg.style.display = "none";
                        alert("节点id不能为空字符串或具有该id的节点不存在！");
                    }
                }
            }
        };//end getNodes
        
        
        /***Ajax部分***/
        /**
          *创建XMLHttpRequest实例
          */
        this.createXMLHttpRequest = function(){
            if(window.ActiveXObject){
                return new ActiveXObject("Microsoft.XMLHttp");
            }else if(window.XMLHttpRequest){
                return new XMLHttpRequest();
            }else{
                return null;
            }
        };
        
        /**
          *返回要查询的URL字符串
          */
        this.createQueryString = function(queryArray){
            var queryString = null;
            for(var i=-1;queryArray!=null&&i<queryArray.length;i++){
                if(i == -1){
                    queryString = "timeStamp=" + new Date().getTime();  //避免由于queryString的相同导致取缓存
                }else if(queryArray[i] != null){
                    queryString = queryString + "&" + queryArray[i][0] + "=" + queryArray[i][1];
                }
            }
            return queryString;
        };
        
        /**
          *用get查询
          */
        this.doRequestUsingGet = function(flag,id){
            isDownLoading = true;
            if(this.xmlHttpRequest == null){
                return;
            }
            xmlHttpRequest.onreadystatechange = function(){
                handleStateChange(flag,id);
            };
            xmlHttpRequest.open("GET",this.serverUrl+"?"+queryString,true);
            xmlHttpRequest.send(null);
        };
        
        /**
          *用post查询
          */
        this.doRequestUsingPost = function(flag,id){
            isDownLoading = true;
            if(xmlHttpRequest == null){
                return;
            }
            
            this.readyState = "loading";  //将树形的状态改为正在加载数据
            
            xmlHttpRequest.open("POST",this.serverUrl,true);
            xmlHttpRequest.setRequestHeader("Content-Length",queryString.length);  
            xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            xmlHttpRequest.onreadystatechange = function(){
                handleStateChange.call(loader,flag,id);  //call,传Tree的this
            };
            xmlHttpRequest.send(queryString);
            
        };
        
        /**
          *检查XMLHttpRequest的readyState属性的状态值，
          *根据flag的值来选择相应的函数操作
          * 1 创建树时生成根节点
          */
        var handleStateChange = function(flag,id){
            if(xmlHttpRequest!=null){
                if(xmlHttpRequest.readyState == 4){
                    if(xmlHttpRequest.status == 200){
                        isDownLoading = false;  //还原初值
                        this.readyState = "loaded";  //将树形的状态改为数据加载完
                        try{
                            returnJson = eval('(' + xmlHttpRequest.responseText + ')');  //将服务器端Json格式数据解析
                            waitingImg.style.display = "none";  //加载、解析成功后，等待图片消失(由于在doRequestUsingPost中使用了call，将Tree的this传进来了)
                        }catch(exception){
                            waitingImg.style.display = "none";
                            return;            
                        }

                        if(returnJson == null || returnJson == "" || flag == null || id == null){
                            return;
                        }
                        
                        switch(flag){
                            case 1: setTimeout(function(){createWebTreeByJson.call(loader,1,id);},2); break;  //call,传Tree的this,加个计时器是为了让等待图片隐藏
                            case 2: setTimeout(function(){createWebTreeByJson.call(loader,2,id);},2); break;  //根据Json的值来生成子节点
                            case 3: getCheckedReturn.call(loader,true); break;
                            case 4: insertNodeReturn.call(loader,true); break;  //插入节点
                            case 5: deleteNodeReturn.call(loader,true); break;  //删除节点
                            case 6: searchNodeReturn.call(loader,true); break;  //搜索节点
                            case 7: getDirChildrenReturn.call(loader,true); break;  //获得直接子节点
                            case 8: getAllChildrenReturn.call(loader,true); break;  //获得全部子节点
                        }
                    }else{
                        isDownLoading = false;  //还原初值
                        waitingImg.style.display = "none";
                        switch(flag){
                            case 1: alert("节点加载失败！Error:HTTP "+xmlHttpRequest.status+"!"); break;
                            case 2: alert("节点加载失败！Error:HTTP "+xmlHttpRequest.status+"!"); break;
                            case 3: getCheckedReturn.call(loader,false); break;
                            case 4: insertNodeReturn.call(loader,false); break;
                            case 5: deleteNodeReturn.call(loader,false); break;
                            case 6: searchNodeReturn.call(loader,false); break;
                            case 7: getDirChildrenReturn.call(loader,false); break;
                            case 8: getAllChildrenReturn.call(loader,false); break;
                        }
                    }
                }
            }
        };
        
        /**
          *处理提交请求后的结果（初始化树时生成根节点）
          *
          */
        var createWebTreeByJson = function(flag,id){
            if(returnJson.succed != null && returnJson.succed == 0){
                alert("加载节点失败:"+returnJson.error);
                return;
            }
            
            var parentRow;
            if(parentLoadNode != null){
                parentRow = parentLoadNode;
                parentLoadNode = null;  //把这个公共变量再清空
            }else{  //用id得可能会有问题，如单位树中分组方案可能有多个id相同的节点
                parentRow = $(id);
            }
            var parentNextRow;
	        var isPage;
		    var parentLayer;
			var chckFlg;
			var isAll = returnJson.isAll == 1 ? true : false;  //是否是一次展开所有子节点
            if(parentRow !=null){  //当取根节点的时候，由于设虚拟根节点标识为空字符串，所以panretRow为空
                parentNextRow = parentRow.nextSibling;
	    		isPage = (parentRow.getAttribute("next") == "1");
		    	if(isPage){  //如果是分页节点那么chckFlg取分页节点的父节点的chckFlg
		    	    var pageParentRow = getParentRow.call(loader,parentRow);
		    	    if(pageParentRow != null){
		    	        chckFlg = pageParentRow.getAttribute("chckFlg");
		    	    }else{
		    	        chckFlg = parentRow.getAttribute("chckFlg");
		    	    }
		    	    parentLayer = parseInt(parentRow.getAttribute("layer")) - 1;
		    	}else{
  			        chckFlg = parentRow.getAttribute("chckFlg");
  			        parentLayer = parseInt(parentRow.getAttribute("layer"));
		    	}
            }else if(flag ==1){  //根结点的父节点(虚拟的)层级为0
                parentLayer = 0;
            }
            
            //更新被点击的行的相关属性
            if(flag == 2 && returnJson.nodes!=null){  
                parentRow.setAttribute("count",(parseInt(parentRow.getAttribute("count"))+returnJson.nodes.length));  //当点击节点加载了新的子节点，要把到根节点路径上的所有节点count属性更新
                if(isPage){  //分页节点要删掉，所以count要减1
                    updateParentCount(parentRow,returnJson.nodes.length - 1);
                }else{
                    updateParentCount(parentRow,returnJson.nodes.length);
                }
                parentRow.setAttribute("loaded",1);  //子节点加载后，loaded属性设为已加载
            }
            
            for(var i=0;i<returnJson.nodes.length;i++){
                var newRow = $C("tr");
                
                if(flag == 1){  //传进来的id是树的div的id
                    treeTbody.appendChild(newRow);
                }else if(flag == 2){  //传进来的id是树的节点行id
                    treeTbody.insertBefore(newRow,parentNextRow);
                }
                for(var j=-1;j<this.extendColCount;j++){
                    if(j==-1){  //树节点
                        var newCell = treeCell.cloneNode(true);
                        newRow.appendChild(newCell);
                                
                                
                        //给节点的tr赋属性
                        var layer = parentLayer + toChangeNull(returnJson.nodes[i].toLayer);
                        newRow.setAttribute("layer",layer);  //节点所在的层数
                        
                        newRow.setAttribute("count",toChangeNull(returnJson.nodes[i].count));  //用于记录当点击该节点时要折叠或展开的行数
                        if(returnJson.nodes[i].next == 1){  //只有分页节点才有下面的两个属性
                            newRow.setAttribute("next","1");  //节点是否为分页节点
                            newRow.setAttribute("pNum",toChangeNull(returnJson.nodes[i].pNum));  //当前页码
                            newRow.setAttribute("parent",toChangeNull(returnJson.nodes[i].parent));  //分页节点的父节点
                        }
                        newRow.setAttribute("id",nodeToRowId(toChangeNull(returnJson.nodes[i].id)));  //节点id(这里在id的前面加上树形容器div的id，用于在一个页面中显示多棵有相同节点的树)
                        newRow.setAttribute("container",toChangeNull(returnJson.nodes[i].container));  //节点是否为容器节点
                        newRow.setAttribute("folder",toChangeNull(returnJson.nodes[i].folder));
                        newRow.setAttribute("openFolder",toChangeNull(returnJson.nodes[i].openFolder));
                        newRow.setAttribute("leaf",toChangeNull(returnJson.nodes[i].leaf));
                        newRow.setAttribute("selected",toChangeNull(returnJson.nodes[i].selected));
                        if(isAll && this.isShiftLoadAllChildren){  //一次展开所有子节点
                            newRow.setAttribute("expanded",1);  //节点是否展开，展开
                            newRow.setAttribute("loaded",1);  //子节点均已加载
                        }else{
                            newRow.setAttribute("expanded",0);  //节点是否展开，第一次加载默认均为不展开
                            newRow.setAttribute("loaded",0);  //子节点未加载
                        }
                                
                        var attributesTemp = returnJson.nodes[i].attributes;
                        var attriStr = "";
                        for(var k=0;attributesTemp!=null&&k<attributesTemp.length;k++){  //加附加属性 (key+逗号+value)+分号+(key+逗号+value)
                            attriStr = attriStr + unescape(toChangeNull(attributesTemp[k][0])) + "," + unescape(toChangeNull(attributesTemp[k][1])) + ";";
                        }
                        newRow.setAttribute("attrs",attriStr);
                        
                        if(chckFlg == "1"){  //如果父节点有这个标记，则子节点全部有这个标记（按shift键选择全部子节点）
                            newRow.setAttribute("chckFlg",1);
                        }
                        
                                    
                        //给节点的tr加相关图标以及checkbox、label等
                        var newExpandIcon = null;  //加"加号"图标，如果一次展开所有节点则是加减号图标
						if(returnJson.nodes[i].first == 1 && !isPage){  //该层第一个节点,如果只是一个分页则不是第一个节点
						    newRow.setAttribute("first",1);
						    if(returnJson.nodes[i].end == 1){  //该层只有一个节点
								newRow.setAttribute("end",1);
								if(layer == 1){  //根节点
								    if(returnJson.nodes[i].container != 0){  //容器节点
								        if(isAll && this.isShiftLoadAllChildren){
								           newExpandIcon = subIcon1.cloneNode(true);
								        }else{
          								    newExpandIcon = plusIcon1.cloneNode(true);
								        }
								    }else{
								        newExpandIcon = emptyIcon.cloneNode(true);
								    }
								}else{
								    if(returnJson.nodes[i].container != 0){
								        if(isAll && this.isShiftLoadAllChildren){
								           newExpandIcon = subIcon4.cloneNode(true);
								        }else{
          								    newExpandIcon = plusIcon4.cloneNode(true);
								        }
								    }else{
								        newExpandIcon = lineIcon3.cloneNode(true);
								    }
								}
							}else{
							    if(layer == 1){
							        if(returnJson.nodes[i].container != 0){
							            if(isAll && this.isShiftLoadAllChildren){
								           newExpandIcon = subIcon2.cloneNode(true);
								        }else{
          								    newExpandIcon = plusIcon2.cloneNode(true);
								        }
								    }else{
								        newExpandIcon = lineIcon1.cloneNode(true);
								    }
							    }else{
							        if(returnJson.nodes[i].container != 0){
							            if(isAll && this.isShiftLoadAllChildren){
								           newExpandIcon = subIcon3.cloneNode(true);
								        }else{
          								    newExpandIcon = plusIcon3.cloneNode(true);
								        }
								    }else{
								        newExpandIcon = lineIcon2.cloneNode(true);
								    }
							    }
							}
						}else if(returnJson.nodes[i].end == 1){  //判断是否为该层最后一个节点
						    newRow.setAttribute("end",1);
						    if(returnJson.nodes[i].container != 0){
						        if(isAll && this.isShiftLoadAllChildren){
								    newExpandIcon = subIcon4.cloneNode(true);
								}else{
          						    newExpandIcon = plusIcon4.cloneNode(true);
								}
							}else{
								newExpandIcon = lineIcon3.cloneNode(true);
							}
						}else{
						    if(returnJson.nodes[i].container != 0){
						        if(isAll && this.isShiftLoadAllChildren){
								    newExpandIcon = subIcon3.cloneNode(true);
								}else{
          						    newExpandIcon = plusIcon3.cloneNode(true);
								}
							}else{
								newExpandIcon = lineIcon2.cloneNode(true);
							}
						}
                        newCell.appendChild(newExpandIcon);
                        
                        
                        addEmptyIcons(newRow);  //加连接线图标和空白图标
                        
                        
                        var newNodeIcon = null;  //加节点图标
                        if(returnJson.nodes[i].container == 0){  //叶子节点
                            if(toChangeNull(returnJson.nodes[i].leaf) != ""){  //如果专门为该节点定义了叶子节点
                                newNodeIcon = imgTemp.cloneNode(true);
                                newNodeIcon.setAttribute("src",returnJson.nodes[i].leaf);
                                newNodeIcon.setAttribute("flag",2);
                            }else{
                                newNodeIcon = leafNodeIcon.cloneNode(true);
                            }
                        }else{
                            if(!isAll){  //如果不是一次展开所有节点 
                                if(toChangeNull(returnJson.nodes[i].folder) != ""){  //如果开发者专门为这个节点定义了folder图标
                                    newNodeIcon = imgTemp.cloneNode(true);
                                    newNodeIcon.setAttribute("src",returnJson.nodes[i].folder);
                                    newNodeIcon.setAttribute("flag",2);
                                }else{
                                    newNodeIcon = nodeIcon.cloneNode(true);
                                }
                            }else if(this.isShiftLoadAllChildren){  //一次展开所有节点，所有节点图标为被打开的
                                if(toChangeNull(returnJson.nodes[i].openFolder) != ""){  //如果开发者专门为这个节点定义了folder图标
                                    newNodeIcon = imgTemp.cloneNode(true);
                                    newNodeIcon.setAttribute("src",returnJson.nodes[i].openFolder);
                                    newNodeIcon.setAttribute("flag",2);
                                }else{
                                    newNodeIcon = openNode.cloneNode(true);
                                }
                            }
                        }
                        newCell.appendChild(newNodeIcon);
                        
                        if(this.isShowCheckbox && returnJson.nodes[i].chekbox == 1){  //加checkbox
                            var newCheckbox = treeCheckbox.cloneNode(true);
                            newCell.appendChild(newCheckbox);
                            if(returnJson.nodes[i].checked == 1){
                                setCheckBoxMode.call(loader,newCheckbox,1);
                            }else if(returnJson.nodes[i].checked == 2){
                                setCheckBoxMode.call(loader,newCheckbox,2);
                            }else if(chckFlg == "1" && returnJson.nodes[i].checked != 3){  //父节点有这个标记，则子节点要被勾选
                                setCheckBoxMode.call(loader,newCheckbox,1);
                            }else if(chckFlg == "2" && returnJson.nodes[i].checked != 3){  //父节点有这个标记，则直接子节点勾选
                                if(layer - parentLayer == 1){
                                    setCheckBoxMode.call(loader,newCheckbox,1);
                                }
                            }else{
                                setCheckBoxMode.call(loader,newCheckbox,3);
                            }
                        }
                                    
                        var newLabel = treeLabel.cloneNode(true);
                        newCell.appendChild(newLabel);
                        newLabel.innerHTML = unescape(toChangeNull(returnJson.nodes[i].name));
                                    
                        //设置label的相关属性，包括事件等
                        newLabel.setAttribute("title",unescape(toChangeNull(returnJson.nodes[i].hint)));
                        $sstyle(newLabel,$gstyle(newLabel) + ";" + toChangeNull(returnJson.nodes[i].style));//节点样式
                        
                        addRowEvent(newRow);  //增加事件属性
                        
                    }else{  //扩展列
                        var newCell = extendCell.cloneNode(true);
                        newRow.appendChild(newCell);
                        var newTextNode = document.createTextNode(" ");
                        newCell.appendChild(newTextNode);
                        if(returnJson.nodes[i].extend != null && returnJson.nodes[i].extend[j] !=null){
                            newTextNode.data = unescape(returnJson.nodes[i].extend[j]);
                        }
                        newCell.style.vAlign = "middle";
                    }
                }
            }
            
            if(isPage){  //如果被点击节点为分页节点，则节点加载完后删除该节点
			    treeTbody.removeChild(parentRow);
			}
            
			this.readyState = "complete";  //将树形的状态改为complete
			//=======创建完节点后响应节点加载完毕事件=======//
			var evFunc = events["onNodesLoadComplete"];
			if(evFunc != null && evFunc.constructor == Function){  //用户绑定了“子节点加载完毕”事件
			    var funcReturn = evFunc();
			    if(funcReturn != null && !funcReturn){  //如果返回false，则不执行下面的后续操作了
			        return;
			    }
			}
            //===========创建完节点后的后续操作===========//
            if(flag ==1 && refresh == null){
                if(this.isAutoToFirstLeafNode){  //自动定位到第一个叶子节点
                    var deep = this.maxDeep;
                    autoToLeafNode.call(loader,1,deep);
                }else if(this.isAutoToFirstNode){  //自动定位到第一个节点
                    $click(treeTbody.firstChild.nextSibling);
                }
            }
            
            if(refresh == 1){  //如果之前做了刷新子节点操作
                if(insertNodeId != null){
                    var insertRow = $(insertNodeId);
                    $click(insertRow);
                    insertNodeId = null;
                }
                refresh = null;
            }
            
            if(refresh == 2){  //如果之前做了刷新当前节点列表操作，需要重新定位刷新之前被选择节点，如果不存在，则定位到上一个节点
                var refreshRowTemp = $(refreshRowId);
                $click(refreshRowTemp);  //刷新之前的节点若不存在则定位到上一行
                refresh = null;
                refreshRowId = null;
                refreshRowIndex = null;
            }
            
        };//end createWebTreeByJson
        
        /**
          * 根据服务器端删除节点传来的结果进行相应操作，是一个事件
          *
          */
        var deleteNodeReturn = function(boolFlag){
            this.readyState = "interactive";  //将树形的状态改为interactive
            var isSuccessed = returnJson.succed;
            var errorInfo = unescape(returnJson.errorInfo);
            var evFunc = events["onDeleteComplete"];
            if(!boolFlag || isSuccessed == 0){  //删除失败
                if(evFunc != null && evFunc.constructor == Function){  //用户绑定了“删除节点结束”事件
                    evFunc(false,errorInfo);
                }else{
                    alert("删除节点失败!");
                }
            }else if(boolFlag && isSuccessed == 1){  //删除成功
                if(evFunc != null && evFunc.constructor == Function){  //用户绑定了“删除节点结束”事件
                    evFunc(true,errorInfo);
                }
            }
			this.readyState = "complete";  //将树形的状态改为complete
			if(deletedRow != null){
				this.refreshSelectedNode(deletedRow);
				deletedRow = null;  //将这个公共变量的值还原为null
			}else{
                this.refreshSelectedNode();  //重新刷新当前选择节点所在的节点列表
			}	
        };//end deleteNodeReturn

        /**
          * 根据服务器端插入节点传来的结果进行相应操作，是一个事件
          *
          */
        var insertNodeReturn = function(boolFlag){
            this.readyState = "interactive";  //将树形的状态改为interactive
            var isSuccessed = returnJson.succed;
            var errorInfo = unescape(returnJson.errorInfo);
            var isRefresh = true;
            var evFunc = events["onInsertComplete"];
            if(!boolFlag || isSuccessed == 0){  //插入失败
                if(evFunc != null && evFunc.constructor == Function){  //用户绑定了“插入节点结束”事件
                    isRefresh = evFunc(false,errorInfo);
                }else{
                    alert("插入节点失败!");
                }
            }else if(boolFlag && isSuccessed == 1){  //插入成功
                if(evFunc != null && evFunc.constructor == Function){  //用户绑定了“插入节点结束”事件
                    isRefresh = evFunc(true,errorInfo);
                }
            }
            this.readyState = "complete";  //将树形的状态改为complete
            if(isRefresh == null ||isRefresh){
                this.refreshSelectedNodeChildren();  //重新刷新当前选择节点所在的节点列表
            } 
        };//end insertNodeReturn
        
        /**
          * 根据在服务器端搜索节点传来的结果进行相应操作，是一个事件
          *
          */
        var searchNodeReturn = function(boolFlag){
            this.readyState = "interactive";  //将树形的状态改为interactive
            if(!boolFlag){  //搜索失败
                searchResult.setNodeIdList(null);
            }else{
                var paths = returnJson.paths;
                if(paths == null){
                    searchResult.setNodeIdList(null);
                }else{
                    //生成SearchResult对象中的节点id数组
                    var nodeIdList = new Array();
                    var arrTemp1 = paths.split("#");
                    if(arrTemp1.length > 0 && arrTemp1[arrTemp1.length - 1] == ""){  //用split函数最后一个可能为空格，如a#得到的数组长度为2
                        arrTemp1.pop();
                    }
                    for(var i=0;i<arrTemp1.length;i++){
                        var arrTemp2 = arrTemp1[i].split(";");
                        nodeIdList.push(arrTemp2);
                    }
                    searchResult.setNodeIdList(nodeIdList);
                    
                    //这里定位到第一组路径
                    var firstPath = nodeIdList[0];
                    if(firstPath != null){
                        locateSomeNode(firstPath,0);  //定位
                    }
                }
            }
            var evFunc = events["onSearchComplete"];
            if(evFunc != null){
                evFunc(searchResult);
            }else{
                if(searchResult == null){
                    alert("搜索失败!");
                }
            }
            this.readyState = "complete";  //将树形的状态改为complete
        };//end searchNodeReturn
        
        /**
          * 根据在服务器端获得直接子节点列表进行相应操作，是一个事件
          *
          */
        var getDirChildrenReturn = function(boolFlag){
            this.readyState = "interactive";  //将树形的状态改为interactive
            var nodeArray = new Array();
            if(boolFlag){
                for(var i=0;i<returnJson.nodes.length;i++){
                    var treeNode = new TreeNode();
                    treeNode.nodeId = returnJson.nodes[i].id;
                    treeNode.nodeName = unescape(toChangeNull(returnJson.nodes[i].name));
                    var attributesTemp = returnJson.nodes[i].attributes;
                    if(attributesTemp != null){
                        for(var k=0;k<attributesTemp.length;k++){
                            treeNode.insertAttribute(unescape(toChangeNull(attributesTemp[k][0])),unescape(toChangeNull(attributesTemp[k][1])));
                        }
                    }
                    nodeArray.push(treeNode);
                }
            }
            
            var evFunc = events["onGetDirChildrenComplete"];
            if(evFunc != null){
                evFunc(nodeArray);
            }
            this.readyState = "complete";  //将树形的状态改为complete
        };//end getDirChildrenReturn
        
        /**
          * 根据在服务器端获得全部子节点列表进行相应操作，是一个事件
          *
          */
        var getAllChildrenReturn = function(boolFlag){
            this.readyState = "interactive";  //将树形的状态改为interactive
            var nodeArray = new Array();
            if(boolFlag){
                for(var i=0;i<returnJson.nodes.length;i++){
                    var treeNode = new TreeNode();
                    treeNode.nodeId = returnJson.nodes[i].id;
                    treeNode.nodeName = unescape(toChangeNull(returnJson.nodes[i].name));
                    var attributesTemp = returnJson.nodes[i].attributes;
                    if(attributesTemp != null){
                        for(var k=0;k<attributesTemp.length;k++){
                            treeNode.insertAttribute(unescape(toChangeNull(attributesTemp[k][0])),unescape(toChangeNull(attributesTemp[k][1])));
                        }
                    }
                    nodeArray.push(treeNode);
                }
            }
            
            var evFunc = events["onGetAllChildrenComplete"];
            if(evFunc != null){
                evFunc(nodeArray);
            }
            this.readyState = "complete";  //将树形的状态改为complete
        };//end getAllChildrenReturn
        
        /**
          * 根据在服务器端得到被checked的节点的子节点id串的结果进行相应操作，是一个事件
          *
          */
        var getCheckedReturn = function(boolFlag){
            this.readyState = "interactive";  //将树形的状态改为interactive
            var checkedIds = null;
            if(boolFlag){
                var ids = returnJson.ids;
                if(ids != null){
                    checkedIds = new Array();
                    if(ids != ""){
                        checkedIds = ids.split(";");
                        if(checkedIds.length > 0 && checkedIds[checkedIds.length - 1] == ""){  //用split函数最后一个可能为空格，如a#得到的数组长度为2
                            checkedIds.pop();
                        }
                        if(checkedBoxes != null){
                            checkedBoxes = checkedBoxes.concat(checkedIds);  //将页面中被checked的checkbox的id数组和服务器端得到的所有子节点id数组合并成一个数组
                        }
                    }
                }
            }
            
            var evFunc = events["onGetCheckedComplete"];
            if(evFunc != null){
                evFunc(checkedBoxes);
            }else{
                if(checkedIds == null){
                    alert("获取子节点标识失败!");
                }
            }
            this.readyState = "complete";  //将树形的状态改为complete
        };//end getCheckedReturn
        
        /***************一些响应事件的函数***************/
        
        /**
          * 给传进来的行对象增加事件属性
          */
        var addRowEvent = function(rowObj){
            if(rowObj == null){
                return;
            }
        
            rowObj.onclick = function(event){  //点击事件
                return onNodeClick.call(loader,event,rowObj);
            };
            
            rowObj.oncontextmenu = function(event){  //右键事件
                return onNodeContentMenu.call(loader,event,rowObj);
            };
            
            rowObj.ondblclick = function(event){  //双击事件 ok
                return onNodeDblClick.call(loader,event,rowObj);
            };
            
            rowObj.onmousedown = function(event){  //按下鼠标事件 ok
                return onNodeMouseDown.call(loader,event,rowObj);
            };
            
            rowObj.onmouseup = function(event){  //释放鼠标事件 ok
                return onNodeMouseUp.call(loader,event,rowObj);
            };
            
            rowObj.onmousemove = function(event){  //鼠标移动事件 ok
                return onNodeMouseMove.call(loader,event,rowObj);
            };
            
            rowObj.onmouseout = function(event){  //鼠标移出事件 ok
                return onNodeMouseOut.call(loader,event,rowObj);
            };
            
            rowObj.onmouseover = function(event){  //鼠标移上事件 ok
                return onNodeMouseOver.call(loader,event,rowObj);
            };
            
            if(document.uniqueID){  //下面的几个事件目前只支持IE
                rowObj.onkeydown = function(event){  //键盘事件
                    return onNodeKeyDown.call(loader,event,rowObj);
                };
                
                rowObj.firstChild.onfocus = function(event){  //获得焦点事件 FF下false
                    return onNodeFocus.call(loader,event,rowObj);
                };
                
                rowObj.firstChild.onblur = function(event){  //失去焦点事件 FF下false
                    return onNodeBlur.call(loader,event,rowObj);
                };
                
                rowObj.onmousewheel = function(event){  //鼠标滚轮事件 FF下false
                    return onNodeMouseWheel.call(loader,event,rowObj);
                };

                rowObj.ondrag = function(event){  //拖拽事件 FF下false
                  return onNodeDrag.call(loader,event,rowObj);
                };
             
                rowObj.ondragend = function(event){  //拖拽结束事件 FF下false
                    return onNodeDragEnd.call(loader,event,rowObj);
                };
            }else{
            
            }
        };
        
        //点击
        var onNodeClick = function(event,rowObj){
            if(rowObj == null || this.readyState != "complete"){
                return;
            }
            
            if(this.isShowMenu){  //点击时隐藏菜单
                if(menuFirst != null){
                    menuFirst.hideMenu();
                }
            }
            
            var eventSrcObj = (event||window.event).target||(event||window.event).srcElement;
            if(eventSrcObj != null){  //有点击事件触发而调用这个函数
            
                //如果点击行的空白处，则不进行下面的操作
                if(eventSrcObj.nodeName == "TD"){  
                    return true;
                }
                
                //如果点击checkbox，根据mode属性来设置checkbox
                if(eventSrcObj.nodeName == "INPUT"){
                    if(eventSrcObj.getAttribute("type") == "checkbox"){
                        if((event||window.event).shiftKey){
                            setCheckboxByKey.call(loader,rowObj,2);
                            if(loader.isShiftLoadAllChildren && rowObj.getAttribute("container") != "0"){
                                loadAllChildrenAgain.call(loader,rowObj);
                            }
                        }else if((event||window.event).ctrlKey){
                            setCheckboxByKey.call(loader,rowObj,3);
                            if(loader.isCtrlLoadAllDirChildren && rowObj.getAttribute("container") != "0"){
                                loadDirChildrenFromPage.call(loader,rowObj);
                            }
                        }else{
                            setCheckboxByKey.call(loader,rowObj,1);
                        }
                        doCustomEventFunc.call(loader,"onCheckboxClick",rowToTreeNode.call(loader,rowObj));
                    }   
                }else{
                    if((event||window.event).shiftKey){  //要将shiftKey传到服务器端
                        shiftKey = true;
                    }else if((event||window.event).ctrlKey){
                        ctrlKey = true;
                    }
                }
                
                //点击了折叠、展开图标
                if(eventSrcObj.nodeName == "IMG" && eventSrcObj.getAttribute("flag") == "1"){  
                    return clickExpandedIcon.call(loader,rowObj);
                }
                
                //点击了节点图标
                if(eventSrcObj == null || (eventSrcObj.nodeName == "IMG" && eventSrcObj.getAttribute("flag") == "2") || eventSrcObj.nodeName == "LABEL" || eventSrcObj.nodeName == "TR"){  
                    return clickNode.call(loader,rowObj);
                }
            }
        };//end onNodeClick
        
        //右键
        var onNodeContentMenu = function(event,rowObj){
            if(rowObj == null){
                return;
            }
            
            var eventSrcObj = (event||window.event).target||(event||window.event).srcElement;
            if(eventSrcObj != null){
                if((eventSrcObj.nodeName == "IMG" && eventSrcObj.getAttribute("flag") == "2") || eventSrcObj.nodeName == "LABEL"){
                    var funcReturn = doCustomEventFunc.call(loader,"onContextMenu",rowToTreeNode.call(loader,rowObj));
                    if(funcReturn != null){
                        if(!funcReturn){
                            return false;
                        }
                    }
                    
                    if(!this.isShowMenu){  //不允许右键菜单
                        return false;
                    }else{  //允许右键菜单
                        //在鼠标的位置显示一级菜单
                        if(menuFirst != null){
							//根据一级菜单Menu实例来处理menuDiv
                            menuFirst.createMenu();
							
                            var ev = event||window.event;
                            menuFirst.hideMenu();
                            menuFirst.setTreeRowId(rowObj.getAttribute("id"));
                            menuFirst.showMenu(ev.clientX,ev.clientY);
                        }
                    }
                }else{
                    return false;
                }
            }
            return false;
        };//end onNodeContentMenu
        
        //键盘
        var onNodeKeyDown = function(event,rowObj){
            if(rowObj == null){
                return;
            }

            if(document.uniqueID){  //FF下tr不能响应键盘事件
                var keyNum = null;  //键盘代码
                keyNum = window.event.keyCode;
                
                var evFunc = events["onKeyDown"];
                if(evFunc != null && evFunc.constructor == Function){  //用户绑定了“节点点击”事件
                    var funcReturn = evFunc(rowObj,keyNum);
                    if(funcReturn != null && !funcReturn){
                        return false;
                    }
                }
                
                if(keyNum == 37){  //左方向键
                    if(rowObj.getAttribute("expanded") == "1"){
                        dealNodeExpanded(rowObj,false);
                        changeExpandedState.call(loader,rowObj);  //变换折叠、展开图标
                    }
                }else if(keyNum == 38){  //上方向键
                    var previouseTempRow = rowObj.previousSibling;
                    while(true){
                        if(previouseTempRow == null || previouseTempRow.previousSibling == null){
                            break;
                        }else if(previouseTempRow.style.display != "none"){
                            changeSelected.call(loader,previouseTempRow);
                            break;
                        }else{
                            previouseTempRow = previouseTempRow.previousSibling;
                        }
                    }
                }else if(keyNum == 39){  //右方向键
                    if(rowObj.getAttribute("expanded") == "0"){
                        if(rowObj.getAttribute("container") == "1"){
                            if(rowObj.getAttribute("loaded") == "0"){
                                parentLoadNode = rowObj;  //给这个公共变量赋值，即将加载的子节点以该行为父节点
                                this.dealRequest(2,rowToNodeId(rowObj.getAttribute("id")));
                            }else{
                                dealNodeExpanded(rowObj,true);
                            }
                            changeExpandedState(rowObj);  //变换折叠、展开图标
                        }
                    }
                }else if(keyNum == 40){  //下方向键
                    var nextTempRow = rowObj.nextSibling;
                    while(true){
                        if(nextTempRow == null){
                            break;
                        }else if(nextTempRow.style.display != "none"){
                            changeSelected.call(loader,nextTempRow);
                            break;
                        }else{
                            nextTempRow = nextTempRow.nextSibling;
                        }
                    }
                }else if(keyNum == 32){  //空格键
                    if(this.isShowCheckbox){
                        if(selectedNode != null){
                            var checkboxObj = getCheckboxByRow(selectedNode);
                            if(checkboxObj != null){
                                checkboxObj.click();
                            }
                        }
                    }
                }
                //    keyNum = event.which;
            }
            return false;
        };//end onNodeKeyDown
        
        //获得焦点
        var onNodeFocus = function(event,rowObj){
            if(rowObj == null){
                return false;
            }
            
            var eventSrcObj = (event||window.event).target||(event||window.event).srcElement;
            if(eventSrcObj != null){
                if((eventSrcObj.nodeName == "IMG" && eventSrcObj.getAttribute("flag") == "2") || eventSrcObj.nodeName == "LABEL" || eventSrcObj.nodeName == "TD"){
                    var funcReturn = doCustomEventFunc.call(loader,"onSelected",rowToTreeNode.call(loader,rowObj));
                    if(funcReturn != null){
                        if(!funcReturn){
                            return false;
                        }
                    }
                }
            }
            return true;
        };
        
        //失去焦点
        var onNodeBlur = function(event,rowObj){
            if(rowObj == null){
                return false;
            }
            
            var eventSrcObj = (event||window.event).target||(event||window.event).srcElement;
            if(eventSrcObj != null){
                if((eventSrcObj.nodeName == "IMG" && eventSrcObj.getAttribute("flag") == "2") || eventSrcObj.nodeName == "LABEL" || eventSrcObj.nodeName == "TD"){
                    var funcReturn = doCustomEventFunc.call(loader,"onBlur",rowToTreeNode.call(loader,rowObj));
                    if(funcReturn != null){
                        if(!funcReturn){
                            return false;
                        }
                    }
                }
            }
            return true;
        };
        
        //双击
        var onNodeDblClick = function(event,rowObj){
            if(rowObj == null){
                return false;
            }
            
            var eventSrcObj = (event||window.event).target||(event||window.event).srcElement;
            if(eventSrcObj != null){
                if((eventSrcObj.nodeName == "IMG" && eventSrcObj.getAttribute("flag") == "2") || eventSrcObj.nodeName == "LABEL" ){
                    var funcReturn = doCustomEventFunc.call(loader,"onDblClick",rowToTreeNode.call(loader,rowObj));
                    if(funcReturn != null){
                        if(!funcReturn){
                            return false;
                        }
                    }
                }
            }
            return false;
        };//end onNodeDblClick
        
        //按下鼠标
        var onNodeMouseDown = function(event,rowObj){
            if(rowObj == null){
                return false;
            }
            
            var eventSrcObj = (event||window.event).target||(event||window.event).srcElement;
            if(eventSrcObj != null){
                if((eventSrcObj.nodeName == "IMG" && eventSrcObj.getAttribute("flag") == "2") || eventSrcObj.nodeName == "LABEL" ){
                    var funcReturn = doCustomEventFunc.call(loader,"onMouseDown",rowToTreeNode.call(loader,rowObj));
                    if(funcReturn != null){
                        if(!funcReturn){
                            return false;
                        }
                    }
                }
            }
        };//end onNodeMouseDown
        
        //释放鼠标
        var onNodeMouseUp = function(event,rowObj){
            if(rowObj == null){
                return false;
            }
            
            var eventSrcObj = (event||window.event).target||(event||window.event).srcElement;
            if(eventSrcObj != null){
                if((eventSrcObj.nodeName == "IMG" && eventSrcObj.getAttribute("flag") == "2") || eventSrcObj.nodeName == "LABEL" ){
                    var funcReturn = doCustomEventFunc.call(loader,"onMouseUp",rowToTreeNode.call(loader,rowObj));
                    if(funcReturn != null){
                        if(!funcReturn){
                            return false;
                        }
                    }
                }
            }
        };//end onNodeMouseUp
        
        //移动鼠标
        var onNodeMouseMove = function(event,rowObj){
            if(rowObj == null){
                return false;
            }
            
            var eventSrcObj = (event||window.event).target||(event||window.event).srcElement;
            if(eventSrcObj != null){
                if((eventSrcObj.nodeName == "IMG" && eventSrcObj.getAttribute("flag") == "2") || eventSrcObj.nodeName == "LABEL" ){
                    var funcReturn = doCustomEventFunc.call(loader,"onMouseMove",rowToTreeNode.call(loader,rowObj));
                    if(funcReturn != null){
                        if(!funcReturn){
                            return false;
                        }
                    }
                }
            }
        };//end onNodeMouseMove
        
        //移出鼠标
        var onNodeMouseOut = function(event,rowObj){
            if(rowObj == null){
                return false;
            }
            
            var eventSrcObj = (event||window.event).target||(event||window.event).srcElement;
            if(eventSrcObj != null){
                if((eventSrcObj.nodeName == "IMG" && eventSrcObj.getAttribute("flag") == "2") || eventSrcObj.nodeName == "LABEL" ){
                    var funcReturn = doCustomEventFunc.call(loader,"onMouseOut",rowToTreeNode.call(loader,rowObj));
                    if(funcReturn != null){
                        if(!funcReturn){
                            return false;
                        }
                    }
                }
            }
        };//end onNodeMouseOut
        
        //移上鼠标
        var onNodeMouseOver = function(event,rowObj){
            if(rowObj == null){
                return false;
            }
            
            var eventSrcObj = (event||window.event).target||(event||window.event).srcElement;
            if(eventSrcObj != null){
                if((eventSrcObj.nodeName == "IMG" && eventSrcObj.getAttribute("flag") == "2") || eventSrcObj.nodeName == "LABEL" ){
                    var funcReturn = doCustomEventFunc.call(loader,"onMouseOver",rowToTreeNode.call(loader,rowObj));
                    if(funcReturn != null){
                        if(!funcReturn){
                            return false;
                        }
                    }
                }
            }
        };//end onNodeMouseOver
        
        //滚轮事件
        var onNodeMouseWheel = function(event,rowObj){
            if(rowObj == null){
                return false;
            }
            
            var eventSrcObj = (event||window.event).target||(event||window.event).srcElement;
            if(eventSrcObj != null){
                if((eventSrcObj.nodeName == "IMG" && eventSrcObj.getAttribute("flag") == "2") || eventSrcObj.nodeName == "LABEL" || eventSrcObj.nodeName == "TD"){
                    var funcReturn = doCustomEventFunc.call(loader,"onMouseWheel",rowToTreeNode.call(loader,rowObj));
                    if(funcReturn != null){
                        if(!funcReturn){
                            return false;
                        }
                    }
                }
            }
        };
        
        //拖拽
        var onNodeDrag = function(event,rowObj){
            if(rowObj == null){
                return false;
            }
            
            var eventSrcObj = (event||window.event).target||(event||window.event).srcElement;
            if(eventSrcObj != null){
                if((eventSrcObj.nodeName == "IMG" && eventSrcObj.getAttribute("flag") == "2") || eventSrcObj.nodeName == "LABEL"){
                    var funcReturn = doCustomEventFunc.call(loader,"onDrag",rowToTreeNode.call(loader,rowObj));
                    if(funcReturn != null){
                        if(!funcReturn){
                            return false;
                        }
                    }
                }
            }
        };
        
        //拖拽结束
        var onNodeDragEnd = function(event,rowObj){
            if(rowObj == null){
                return false;
            }
            
            var eventSrcObj = (event||window.event).target||(event||window.event).srcElement;
            if(eventSrcObj != null){
                if((eventSrcObj.nodeName == "IMG" && eventSrcObj.getAttribute("flag") == "2") || eventSrcObj.nodeName == "LABEL"){
                    var funcReturn = doCustomEventFunc.call(loader,"onDragEnd",rowToTreeNode.call(loader,rowObj));
                    if(funcReturn != null){
                        if(!funcReturn){
                            return false;
                        }
                    }
                }
            }
        };
        
        
        //运行用户自定义事件函数
        var doCustomEventFunc = function(eventName,treeNode){
            var evFunc = events[eventName];
            if(evFunc != null && evFunc.constructor == Function){  //用户绑定了“节点点击”事件
                return evFunc(treeNode);
            }else{
                return null;
            }
        };
        
        
        
        /***工具函数***/
        
        var toChangeNull = function(data){  //将值为null的变量转为空字符串返回
            if(data == null){
                return "";
            }else{
                return data;
            }
        };
        
        var toNull = function(obj){  //将用过的对象设为null（javascript好像自动回收值为null的对象）
            obj = null;
        };
        
        var initShiftCtrl = function(shift, ctrl){
            if(shift == null && ctrl == null){
                shiftKey = false;
            }else{
                shiftKey = shift;
            }
            if(ctrl == null){
                ctrlKey = false;
            }else{
                ctrlKey = ctrl;
            }
            shiftCtrlChecked = null;
        };
        
        var getCheckboxByRow = function(rowObj){
            if(rowObj == null){
                return null;
            }
            var inputObjs = rowObj.getElementsByTagName("input");
            for(var i=0;inputObjs!=null&&i<inputObjs.length;i++){
                if(inputObjs[i].getAttribute("type") == "checkbox"){
                    return inputObjs[i];
                }
            }
            return null;
        };
          
        /**
          * 点击节点图标及label的操作
          */
        var clickNode = function(rowObj){
            var isPage = rowObj.getAttribute("next") == "1";  //是否是分页节点
            
            if(!isPage){
                if(selectedNode == null || selectedNode.getAttribute("id") != rowObj.getAttribute("id")){  //如果当前点击的节点id和记录的当前被选择的节点id不相同，即切换节点
                    var nodeChangingEv = events["onNodeChanging"];
                    if(nodeChangingEv != null && nodeChangingEv.constructor == Function){  //如果用户绑定了“节点切换”事件
                        var funReturn = nodeChangingEv(rowToTreeNode.call(loader,rowObj));
                        if(!funReturn){  //如果开发者的函数返回false则终止切换节点
                            initShiftCtrl();
                            return false;
                        }
                    }
                }
        
                changeSelected.call(loader,rowObj);  //处理当前被选择
        
                var funReturn = doCustomEventFunc.call(loader,"onClick",rowToTreeNode.call(loader,rowObj));  //用户自定义函数
                if(funReturn != null){
                    if(!funReturn){
                        initShiftCtrl();
                        return false;  //如果开发者的函数返回false则终止点击操作
                    }
                }
            
                if(this.isCollapseOtherNodes){  //点击该节点,同层节点
                    collapseSameLayerNodes(rowObj);
                }
            
            
                //根据expanded和container和loaded属性来判断是否要向服务器发送请求,生成子节点
              
                if(rowObj.getAttribute("container") == "0"){ //非容器节点
                    initShiftCtrl();
                    return true;
                }
            }
            
            if(rowObj.getAttribute("loaded") == "0"){  //子节点未加载
                parentLoadNode = rowObj;  //给这个公共变量赋值，即将加载的子节点以该行为父节点
                this.dealRequest(2,rowToNodeId(rowObj.getAttribute("id")));
            }else if(rowObj.getAttribute("loaded") == "1" && !isPage){  //子节点已加载
                //if(shiftKey && this.isShiftLoadAllChildren){  //如果按住了shift键,并且允许ShiftLoadAllChildren
                //    loadAllChildrenAgain.call(loader,rowObj);
                //}else 
                if(rowObj.getAttribute("expanded") == "0"){  //节点折叠，则展开子节点
                    dealNodeExpanded(rowObj,true);
                }else if(rowObj.getAttribute("expanded") == "1"){  //节点展开,则收回子节点
                    if(funReturn != null && funReturn){  //默认情况下，如果点击事件没有绑定函数或绑定了但没返回true，则如子节点加载过且展开，则不收回
                        dealNodeExpanded(rowObj,false);
                    }else{
			            initShiftCtrl();
                        return true;  //不用执行下面的变换折叠展开图标函数
                    }
                }                
            }
               
            changeExpandedState.call(loader,rowObj);  //变换折叠、展开图标
            
            //shift和ctrl恢复初值
            initShiftCtrl();
            return true;
        };
		
        
        /**
          * 点击折叠、展开图标的操作
          */
        var clickExpandedIcon = function(rowObj){
            if(selectedNode != null){
                var selectedRow = selectedNode;//$(selectedNode.getAttribute("id"));
                if(selectedRow != null && rowObj.getAttribute("expanded") != "0"){
                    if(compareParentsNode(selectedRow,rowObj)){  //如果记录的当前被选择的节点是rowObj的子节点（有可能是多重的），则把rowObj设为被选择
                        if(selectedNode == null || selectedNode.getAttribute("id") != rowObj.getAttribute("id")){  //如果当前点击的节点id和记录的当前被选择的节点id不相同，即切换节点
                            var nodeChangingEv = events["onNodeChanging"];
                            if(nodeChangingEv != null && nodeChangingEv.constructor == Function){  //如果用户绑定了“节点切换”事件
                                var funReturn = nodeChangingEv(rowToTreeNode.call(loader,rowObj));
                                if(!funReturn){  //如果开发者的函数返回false则终止切换节点
                                    initShiftCtrl();
                                    return false;
                                }
                            }
                        }
            
                        changeSelected.call(loader,rowObj);  //处理当前被选择
        
                        doCustomEventFunc.call(loader,"onClick",rowToTreeNode.call(loader,rowObj));  //用户自定义函数
                    }
                }
            }
            
            if(rowObj.getAttribute("container") == "0"){ //非容器节点
                initShiftCtrl();
                return true;
            }
                    
            if(rowObj.getAttribute("loaded") == "0"){  //子节点未加载
                parentLoadNode = rowObj;  //给这个公共变量赋值，即加载的节点以该行为父节点
                this.dealRequest(2,rowToNodeId(rowObj.getAttribute("id")));
            }else if(rowObj.getAttribute("loaded") == "1"){  //子节点已加载
                //if(shiftKey && this.isShiftLoadAllChildren){  //如果按住了shift键,并且允许ShiftLoadAllChildren
                //    loadAllChildrenAgain.call(loader,rowObj);
                //}else 
                if(rowObj.getAttribute("expanded") == "0"){  //节点折叠，则展开子节点
                    dealNodeExpanded(rowObj,true);
                }else if(rowObj.getAttribute("expanded") == "1"){  //节点展开,则收回子节点
                    dealNodeExpanded(rowObj,false);
                }
            }

            changeExpandedState.call(loader,rowObj);//变换折叠、展开图标

            changeNodeIcon.call(loader,rowObj);  //变换节点图标
            
            //shift和ctrl恢复初值
            initShiftCtrl();
            return true;
        };
        
        /**
          * 当点击某节点,同时收起它同层的展开节点
          */
        var collapseSameLayerNodes = function(rowObj){
            if(rowObj == null){
                return;
            }
            var rowObjLayer = parseInt(rowObj.getAttribute("layer"));
            var rowTemp = rowObj;
            
            while(true){  //往上找
                rowTemp = rowTemp.previousSibling;
                if(rowTemp == null){  //第一个节点了
                    break;
                }
                var rowTempLayer = parseInt(rowTemp.getAttribute("layer"));
                if(rowTempLayer == rowObjLayer){
                    if(rowTemp.getAttribute("expanded") == "1"){  //这个同层节点已展开则需要折叠
                        clickExpandedIcon(rowTemp);
                    }
                }else if(rowTempLayer == rowObjLayer -1){
                    break;
                }
            }
            
            rowTemp = rowObj;
            while(true){  //往下找
                rowTemp = rowTemp.nextSibling;
                if(rowTemp == null){  //最后一个节点了
                    break;
                }
                var rowTempLayer = parseInt(rowTemp.getAttribute("layer"));
                if(rowTempLayer == rowObjLayer){
                    if(rowTemp.getAttribute("expanded") == "1"){  //这个同层节点已展开则需要折叠
                        clickExpandedIcon(rowTemp);
                    }
                }else if(rowTempLayer == rowObjLayer -1){
                    break;
                }
            } 
        };
        
        /**
          * 自动定位到第一个叶子节点
          */
        var autoToLeafNode = function(index,count){
            if(this.readyState != "complete" && this.readyState != "init"){
                setTimeout(function(){autoToLeafNode.call(loader,index,count);},200);
            }else{
                var obj = null;
                var rows = null;
                obj = treeTbody;
                rows = obj.childNodes;
                
                if(index >= rows.length){  //树中没有节点
                    return;
                }
                
                if(index != 1){
                    if(count == null || count <= 0 || (parseInt(rows[index].getAttribute("layer")) != (parseInt(rows[index-1].getAttribute("layer")) + 1))){
                        $click(rows[index-1]);
                        if(count != null && count <=0){
                            alert("搜索第一个叶子节点的深度超过"+loader.maxDeep+"!");
                        }
                        return;
                    }
                }
                
                
                if(rows[index].getAttribute("container") == "0"){ //非容器节点
                    $click(rows[index]);
                    return;
                }
                
                clickExpandedIcon.call(loader,rows[index]);
                
                autoToLeafNode.call(loader,index + 1,count - 1);  //递归
            }
        };
        
        /**
          * 定位到某节点
          */
        var locateSomeNode = function(nodepath,index,count){
            if(count == null){
                count = 1;
            }
            if(this.readyState != "complete" && this.readyState != "init"){
                setTimeout(function(){locateSomeNode.call(loader,nodepath,index,count);},200);
            }else{
                if(nodepath != null && nodepath instanceof Array){
                    if(index < nodepath.length){
                        var rowObj = $(nodeToRowId(nodepath[index]));
                        if(rowObj != null){
                            if(nodepath.length - index == 1){  //nodepath里最后一个节点为点击节点图标操作
                                $click(rowObj);
                            }else{  //其余为点击展开折叠图标操作
                                if(rowObj.getAttribute("expanded") == "0"){  //节点未展开，则点开折叠展开图标
                                    clickExpandedIcon.call(loader,rowObj); 
                                }
                            }
                            locateSomeNode(nodepath,index+1);  //递归
                        }else{  //如果该节点不存在，则可能是该节点还没生成出来，或者是有分页
                            if(count % 2 == 0){  //如果每过0.6秒钟还没有找到该节点，则试着去找分页节点并且点击
                                var parentRow;
                                if(index > 0){
                                    parentRow = $(nodeToRowId(nodepath[index - 1]));
                                }
                                expandPageNode.call(loader,parentRow);  //展开parentRow下的子节点列表中的分页节点
                            }else if(count > 50){  //超过10秒则不找了
                                return;
                            }
                            setTimeout(function(){locateSomeNode.call(loader,nodepath,index,++count);},200);
                        }
                    }
                }
            }
        };   
        
        /**
          * 展开parentRow下的子节点列表中的分页节点,locateSomeNode函数中用到
          */
        var expandPageNode = function(rowObj){
            var layer = 1;
            if(rowObj == null){  //如果rowObj为null，则要展开的分页节点是指跟节点列表中的分页节点（如果存在则肯定是最后一个节点）
                rowObjs = treeDiv.getElementsByTagName("tr");
                if(rowObjs != null){
                    var rootPageRow = rowObjs[rowObjs.length -1];
                    if(rootPageRow.getAttribute("next") == "1"){
                        $click(rootPageRow);
                    }
                }else{
                    return;
                }
            }else{
                var layer = parseInt(rowObj.getAttribute("layer"));
                var nextRow = rowObj.nextSibling;
                while(true){
                    if(nextRow == null || parseInt(nextRow.getAttribute("layer")) == layer){  //如果所有下级节点都遍历完了
                        return;
                    }
                    if(parseInt(nextRow.getAttribute("layer")) == layer + 1 && nextRow.getAttribute("end") == "1"){  //rowObj的子节点列表中的最后一个节点
                        if(nextRow.getAttribute("next") == "1"){  //如果是分页节点则展开
                            $click(nextRow);
                        }
                        return;
                    }else{
                        nextRow = nextRow.nextSibling;
                    }
                }
            }
        }
        
        /**
          * 得到父节点行
          */
        var getParentRow = function(rowObj){
            if(rowObj == null){
                return;
            }
        
            var layer = parseInt(rowObj.getAttribute("layer"));
            if(layer == 1){
                return null;
            }else{
                var rowTemp = rowObj;
                while(true){
                    var temp = rowTemp.previousSibling;  //上一行
                    if(temp != null){
                        if(parseInt(temp.getAttribute("layer")) == (layer - 1)){
                            return temp;
                        }else{
                            rowTemp = temp;
                        }
                    }else{
                        return null;
                    }
                }
            }
        };
        
        /**
          * 比较row到根（父）节点之间路径上某节点是否与rowObj相同
          */
        var compareParentsNode = function(row,rowObj){
            if(rowObj == null){
                return;
            }
        
            var rowTemp = getParentRow(row);
            if(rowTemp == null || parseInt(rowTemp.getAttribute("layer")) < parseInt(rowObj.getAttribute("layer"))){  //如果在row的路径上与rowObj的layer属性相同的id不同
                return false;
            }else{
                if(rowTemp == rowObj){
                    return true;
                }else{
                    return compareParentsNode(rowTemp,rowObj);
                }
            }
        };
        
        /**
          * 更新某节点行到根节点路径上的所有节点的count属性，用于加载和删除节点（在处理加载节点时，用到parentEndLayerArr数组，用于记录父节点路径上存在end属性的节点layer）
          */
        var updateParentCount = function(rowObj,count){
            if(rowObj == null){
                return;
            }
        
            var parentRow = getParentRow(rowObj);
            if(parentRow == null){
                return;
            }else{
                var parentCount = count+parseInt(parentRow.getAttribute("count"));
                parentRow.setAttribute("count",parentCount);
                updateParentCount(parentRow,count);
            }
        };
        
        /**
          * 根据节点的count属性来删除该节点下的所有子节点
          */
        var removeChildrenByCount = function(rowObj){
            var count = parseInt(rowObj.getAttribute("count"));
            for(var i=0;i<count;i++){
               var nextRow = rowObj.nextSibling;
               if(nextRow != null){
                   treeTbody.removeChild(rowObj.nextSibling);
               }
            }
                    
            updateParentCount(rowObj,count*(-1));  //更新某节点行到根节点路径上的所有节点的count属性，用于折叠和展开节点
            rowObj.setAttribute("count",0);
        };
        
        /**
          * 无论父节点的子节点是否加载，重新加载所有子节点
          */
        var loadAllChildrenAgain = function(rowObj){
            if(rowObj != null){
	            removeChildrenByCount(rowObj);
	            rowObj.setAttribute("loaded", "0");
	            rowObj.setAttribute("expanded", "0");
	            dealNodeExpanded(rowObj,true);
	            parentLoadNode = rowObj;  //给这个公共变量赋值，即将加载的子节点以该行为父节点
	            shiftKey = true;  //将这个公共变量设为true
	            var checkboxObj = getCheckboxByRow(rowObj);
	            if(checkboxObj != null){
    	            shiftCtrlChecked = checkboxObj.checked;
	            }
	            this.dealRequest(2,rowToNodeId(rowObj.getAttribute("id")));
	            changeExpandedState.call(loader,rowObj);  //变换折叠、展开图标
            }
        };
        
        /**
          * 按ctrl点checkbox
          */
        var loadDirChildrenFromPage = function(rowObj){
            if(rowObj != null){
                if(rowObj.getAttribute("loaded") == "0"){
	                parentLoadNode = rowObj;  //给这个公共变量赋值，即将加载的子节点以该行为父节点
                    ctrlKey = true;  //将这个公共变量设为true
                    var checkboxObj = getCheckboxByRow(rowObj);
		            if(checkboxObj != null){
	    	            shiftCtrlChecked = checkboxObj.checked;
		            }
                    this.dealRequest(2,rowToNodeId(rowObj.getAttribute("id")));
                    changeExpandedState.call(loader,rowObj);  //变换折叠、展开图标
                    return;
                }
                var nextRow = rowObj.nextSibling;
                var layer = parseInt(rowObj.getAttribute("layer"));
                var nextLayer;
                while(nextRow != null){
                    nextLayer = parseInt(nextRow.getAttribute("layer"));
                    if(nextLayer == layer + 1){
                        if(nextRow.getAttribute("next") == "1"){  //分页节点
                            ctrlKey = true;  //将这个公共变量设为true
                            var checkboxObj = getCheckboxByRow(rowObj);
				            if(checkboxObj != null){
			    	            shiftCtrlChecked = checkboxObj.checked;
				            }
				            $click(nextRow);
                            return;
                        }else{
                            nextRow = nextRow.nextSibling;
                            continue;
                        }
                    }else if(nextLayer > layer){
                        nextRow = nextRow.nextSibling;
                        continue;
                    }else{
                        return;
                    }
                }
            }
        };
        
        
        /**
          * 根据tr将相关属性赋给TreeNode对象
          */
        var rowToTreeNode = function(rowObj){
            if(rowObj == null){
                return;
            }
            
            //给“当前被选择的节点”属性赋值
            var treeNode = new TreeNode();
            var rowId = rowObj.getAttribute("id");
            var id = rowToNodeId(rowId);
            treeNode.setNodeId(id);
            var labelObj = rowObj.getElementsByTagName("LABEL")[0];
            treeNode.setNodeName(dataFormat(labelObj.innerHTML));
            
            var arrTemp = null;
            var strTemp = rowObj.getAttribute("attrs");
            if(strTemp != null){
                arrTemp = strTemp.split(";");
            }
            for(var i=0;arrTemp!=null&&i<arrTemp.length;i++){
                var temp = null;
                if(arrTemp[i] != null && arrTemp[i] != ""){
                    temp = arrTemp[i].split(",");
                    if(temp != null){
                        treeNode.insertAttribute(temp[0],temp[1]);
                    }
                }
            }
            
            treeNode.count = parseInt(rowObj.getAttribute("count"));
            
            if(rowObj.getAttribute("expanded") == "1"){
                treeNode.expanded = true;
            }
            
            if(rowObj.getAttribute("container") == "1"){
                treeNode.container = true;
            }
            
            if(rowObj.getAttribute("loaded") == "1"){
                treeNode.loaded = true;
            }
            
            if(rowObj.getAttribute("first") == "1"){
                treeNode.isFirst = true;
            }
            
            if(rowObj.getAttribute("end") == "1"){
                treeNode.isEnd = true;
            }
            
            treeNode.checkMode = this.getCheckStateByNode(id);
            
            treeNode.currentIconPath = rowObj.firstChild.firstChild.nextSibling.src;
            
            if(rowObj.getAttribute("next") == "1"){
                treeNode.isNext = true;
                treeNode.pNum = rowObj.getAttribute("pNum");
            }
            
            treeNode.styleCode = toChangeNull($gstyle(rowObj.getElementsByTagName("label")[0]));
            
            return treeNode;
        };
        
        /**
          * 处理节点的折叠和展开
          */
        var dealNodeExpanded = function(rowObj,boolFlag){
            if(rowObj == null){
                return;
            }
        
            var count = parseInt(rowObj.getAttribute("count"));
            var tempRow = rowObj;
            if(boolFlag){  //展开节点
                for(var i=0;i<count;i++){
                    tempRow = tempRow.nextSibling;
                    tempRow.style.display = "";
                    if(tempRow.getAttribute("expanded") == "0"){  //(展开时处理这一步很重要)该子节点为折叠，则根据其count属性，跳过count行
                        var countTemp = parseInt(tempRow.getAttribute("count"));
                        for(var j=0;j<countTemp;j++){
                            tempRow = tempRow.nextSibling;
                        }
                        i = i + countTemp;
                    }
                }
            }else{  //折叠节点
                for(var i=0;i<count;i++){
                    tempRow = tempRow.nextSibling;
                    tempRow.style.display = "none";
                    if(tempRow.getAttribute("expanded") == "0"){  //该子节点为折叠，则根据其count属性，跳过count行
                        var countTemp = parseInt(tempRow.getAttribute("count"));
                        for(var j=0;j<countTemp;j++){
                            tempRow = tempRow.nextSibling;
                        }
                        i = i + countTemp;
                    }
                }
            }
        };
        
        /**
          * 给行计算并添加空白图标（或连线图标）
          * rowObj新行
          */
        var addEmptyIcons = function(rowObj){
            if(rowObj == null){
                return;
            }
            
            var layer = parseInt(rowObj.getAttribute("layer"));
            var previousParentLayer = 1;
			var previousParentImgs = null;  //上一个节点同级节点的第一个单元格的所有图标对象
			var imgNum = 0;  //上一个节点同级节点的第一个单元格的所有图标个数
            var iconCount = layer;  //根据layer算出空白及连线图片的总数,本来-1的
            var isEnd = false;  //上一个节点是否为所在列表的end节点
            
            var previousParentRow = rowObj.previousSibling;
            var nextParentRow = rowObj.nextSibling;
            if(previousParentRow.previousSibling != null){  //上一行不是表头行
                previousParentLayer = parseInt(previousParentRow.getAttribute("layer"));
                previousParentImgs = previousParentRow.firstChild.getElementsByTagName("img");
                imgNum = previousParentImgs.length;
                isEnd = previousParentRow.getAttribute("end") == "1" ? true : false;
            }
            
            var tdObj = rowObj.firstChild;  //第一个td
            var newIcon = null;
            //加空白图片
            if(layer > previousParentLayer){  //子节点
                if(isEnd){  //上一个节点有end标识，则需要在当前节点加减号图标前加一个空白图标
                    newIcon = emptyIcon.cloneNode(true);
                }else{  //否则加一个连线图标 
                    newIcon = lineIcon4.cloneNode(true);
                }
                tdObj.insertBefore(newIcon,tdObj.firstChild);
            }else if(layer == previousParentLayer){  //同层节点
                  
            }
            if(previousParentLayer > 1){
                var count = 0;  //除了上面的那些准备加的图标外，尚需要从上一个节点克隆的图标数
                if(layer > previousParentLayer){
                    count = previousParentLayer - (layer - previousParentLayer);
                }else{
                    var countTemp = previousParentLayer - layer;
                    count = previousParentLayer - countTemp - 1;
                }
                for(var i=count-1;i>=0;i--){  //克隆下一个 父节点的同级节点的连线图标
                    newIcon = previousParentImgs[i].cloneNode(true);
                    tdObj.insertBefore(newIcon,tdObj.firstChild);
                }
            }
        };
        
        /**
          * 点击节点后，根据expanded属性的变化来设置加减号图标（即折叠、展开图标）的变换
          * rowObj新行
          */
        var changeExpandedState = function(rowObj){
            if(rowObj == null || rowObj.getAttribute("container") == "0"){
                return;
            }
            var icons = rowObj.getElementsByTagName("img");  //rowObj中的所有图标
            var newExpandIcon = null;
            
            //变换折叠、展开图标 和 节点图标
            if(rowObj.getAttribute("expanded") == "0"){ //变成减号
                if(rowObj.getAttribute("first") == "1"){
                    if(rowObj.getAttribute("end") == "1"){
                        if(rowObj.getAttribute("layer") == "1"){
                            newExpandIcon = subIcon1.cloneNode(true);
                        }else{
                            newExpandIcon = subIcon4.cloneNode(true);
                        }
                    }else{
                        if(rowObj.getAttribute("layer") == "1"){
                            newExpandIcon = subIcon2.cloneNode(true);
                        }else{
                            newExpandIcon = subIcon3.cloneNode(true);
                        }
                    }
                }else if(rowObj.getAttribute("end") == "1"){
                    newExpandIcon = subIcon4.cloneNode(true);
                }else{
                    newExpandIcon = subIcon3.cloneNode(true);
                }
                rowObj.setAttribute("expanded",1);
                rowObj.firstChild.replaceChild(newExpandIcon,icons[icons.length-2]);
            }else if(rowObj.getAttribute("expanded") == "1"){  //变成加号
                if(rowObj.getAttribute("first") == "1"){
                    if(rowObj.getAttribute("end") == "1"){
                        if(rowObj.getAttribute("layer") == "1"){
                            newExpandIcon = plusIcon1.cloneNode(true);
                        }else{
                            newExpandIcon = plusIcon4.cloneNode(true);
                        }
                    }else{
                        if(rowObj.getAttribute("layer") == "1"){
                            newExpandIcon = plusIcon2.cloneNode(true);
                        }else{
                            newExpandIcon = plusIcon3.cloneNode(true);
                        }
                    }
                }else if(rowObj.getAttribute("end") == "1"){
                    newExpandIcon = plusIcon4.cloneNode(true);
                }else{
                    newExpandIcon = plusIcon3.cloneNode(true);
                }
                rowObj.setAttribute("expanded",0);
                rowObj.firstChild.replaceChild(newExpandIcon,icons[icons.length-2]);
            }
        };
        
        /**
          * 点击折叠展开节点时节点图标的变换
          */
        var changeNodeIcon = function(rowObj){
            if(rowObj == null){
                return;
            }
        
            var isLoaded = true;
            if(rowObj.getAttribute("loaded") == "0"){
                isLoaded = false;
            }
        
            if(rowObj != null){  
                var folderIconTemp = null; 
                if(rowObj.getAttribute("container") == "0" || (selectedNode != null && selectedNode.getAttribute("id") == rowObj.getAttribute("id"))){  //如果是叶子节则不变
                    return;
                }else if(rowObj.getAttribute("expanded") == "0" && isLoaded){  //要考虑如果该节点没展开则设置加减号图标的操作要在加载后进行，所以那时候恶性panded属性还没有改变
                    if(rowObj.getAttribute("folder") == ""){
                        folderIconTemp = nodeIcon.cloneNode(true);
                    }else{
                        folderIconTemp = imgTemp.cloneNode(true);
                        folderIconTemp.setAttribute("src",rowObj.getAttribute("folder"));
                        folderIconTemp.setAttribute("flag",2);
                    }
                }else if(rowObj.getAttribute("expanded") == "1" || (rowObj.getAttribute("expanded") == "0" && !isLoaded)){
                    if(rowObj.getAttribute("openFolder") == ""){
                        folderIconTemp = openNode.cloneNode(true);
                    }else{
                        folderIconTemp = imgTemp.cloneNode(true);
                        folderIconTemp.setAttribute("src",rowObj.getAttribute("openFolder"));
                        folderIconTemp.setAttribute("flag",2);
                    }
                }
                var iconsTemp = rowObj.getElementsByTagName("img");
                rowObj.childNodes[0].replaceChild(folderIconTemp,iconsTemp[iconsTemp.length-1]);
            }
        };
        
        /**
          * 当选中某节点后的相应处理
          */
        var changeSelected = function(rowObj){
            if(rowObj == null){
                return;
            }
            
            lastSelectedNode = selectedNode;  //将“当前被选择节点”属性的值赋给“上次被选择节点”属性
            selectedNode = rowObj;  //树形的"当前被选择节点"属性赋值
            
			if(lastSelectedNode != selectedNode){
				//将上一个被选择的节点的文字样式恢复正常
				if(lastSelectedNode != null){
    				var parentLabelObj = lastSelectedNode.getElementsByTagName("label")[0];
	    			if(selectedNodeStyle != null){
	    			    $sstyle(parentLabelObj,selectedNodeStyle);
				    }
				}
  		        //重新给公共变量selectedNodeStyle赋值
			    var labelObj = rowObj.getElementsByTagName("label")[0];
			    selectedNodeStyle = $gstyle(labelObj);
			}
			
			
            var icons = rowObj.getElementsByTagName("img");  //rowObj中的所有图标
            //变换当前节点的节点图标为“被选择”图标
            if(toChangeNull(rowObj.getAttribute("selected")) != ""){  //变为“被选择”图标
                newFolderIcon = imgTemp.cloneNode(true);
                newFolderIcon.setAttribute("src",rowObj.getAttribute("selected"));
                newFolderIcon.setAttribute("flag",2);
            }else{
                newFolderIcon = selectedNodeIcon.cloneNode(true);
            }
            rowObj.childNodes[0].replaceChild(newFolderIcon,icons[icons.length-1]);
			
	        //变换当前节点的文字样式为高亮显示
		    var labelObj = rowObj.getElementsByTagName("label")[0];
		    $sstyle(labelObj,selectedNodeStyle + ";" + this.selectedNodeStyleCode);
			
            if(lastSelectedNode != null && lastSelectedNode != selectedNode){  
	            //将上一次被选择的节点的节点图标由“被选择”转换成相应的图标
                var lastSelectedRow = lastSelectedNode;
                if(lastSelectedRow != null){
                    var folderIconTemp = null;
                    if(lastSelectedRow.getAttribute("container") == "0"){  //如果是叶子节点则换为叶子节点图标
                        if(lastSelectedRow.getAttribute("leaf") == ""){
                            folderIconTemp = leafNodeIcon.cloneNode(true);
                        }else{
                            folderIconTemp = imgTemp.cloneNode(true);
                            folderIconTemp.setAttribute("src",lastSelectedRow.getAttribute("leaf"));
                            folderIconTemp.setAttribute("flag",2);
                        }
                    }else if(lastSelectedRow.getAttribute("expanded") == "0"){
                        if(lastSelectedRow.getAttribute("folder") == ""){
                            folderIconTemp = nodeIcon.cloneNode(true);
                        }else{
                            folderIconTemp = imgTemp.cloneNode(true);
                            folderIconTemp.setAttribute("src",lastSelectedRow.getAttribute("folder"));
                            folderIconTemp.setAttribute("flag",2);
                        }
                    }else if(lastSelectedRow.getAttribute("expanded") == "1"){
                        if(lastSelectedRow.getAttribute("openFolder") == ""){
                            folderIconTemp = openNode.cloneNode(true);
                        }else{
                            folderIconTemp = imgTemp.cloneNode(true);
                            folderIconTemp.setAttribute("src",lastSelectedRow.getAttribute("openFolder"));
                            folderIconTemp.setAttribute("flag",2);
                        }
                    }
                    var iconsTemp = lastSelectedRow.getElementsByTagName("img");
                    lastSelectedRow.childNodes[0].replaceChild(folderIconTemp,iconsTemp[iconsTemp.length-1]);
                }
            }
			
            try{
                rowObj.firstChild.focus();  //当前被选择节点获得焦点,主要用于键盘操作时,如果div隐藏则会异常
            }catch(e){}
        };
        
        /**
          * 设置checkbox的状态，1 全选；2 半选；3 未选
          * flag 后来加的一个属性，当true时则只对checkbox进行属性操作
          */
        var setCheckBoxMode = function(checkBoxObj,mode,flag){
            if(checkBoxObj == null){
                return;
            }
            //var basicStyle = ";width:"+this.checkWidth+"px;height:"+this.checkHeight+"px;";
            var basicStyle = "";
            if(mode == 1 || mode == "1"){  //全选
                if(flag == null){
                    checkBoxObj.checked = true;
                }
                checkBoxObj.setAttribute("mode",1);
                checkBoxObj.setAttribute("style",basicStyle);
            }else if(mode == 2 || mode == "2"){  //半选
                if(flag == null){
                    checkBoxObj.checked = true;
                }
                checkBoxObj.setAttribute("mode",2);
                if(document.uniqueID){
                    checkBoxObj.style.filter = "alpha(opacity=30)";
                }else{
                    checkBoxObj.setAttribute("style","filter:alpha(opacity=30);-moz-opacity:0.3"+basicStyle);
                }
            }else if(mode == 3 || mode == "3"){  //未选
                checkBoxObj.setAttribute("mode",3);
                if(document.uniqueID){
                    checkBoxObj.style.filter = "alpha(opacity=100)";
                    if(flag == null){
                        checkBoxObj.checked = false;
                    }
                }else{
                    checkBoxObj.setAttribute("style",basicStyle);
                    if(flag == null){
                        checkBoxObj.checked = false;
                    }
                }
            }
        };
        
        /**
          * 点击checkbox时同时按住了ctrl或shift键的相关处理
          * rowObj 点击的checkbox对应的那一行
          * flag1 1:没有按任何键 ,2:shift ,3:ctrl
          */
        var setCheckboxByKey = function(obj,flag1){
            if(obj != null){
                var rowObj = null;
                if(obj instanceof TreeNode){
                    if(obj.nodeId == null){
                        return;
                    }
                    rowObj = $(nodeToRowId(obj.nodeId));
                }else{
                    rowObj = obj;
                }
                if(rowObj == null){
                    return;
                }
                var checkboxObj = getCheckboxByRow(rowObj);
                if(checkboxObj == null){
                    return;
                }
                var mode = checkboxObj.getAttribute("mode");
                if(flag1 == 1){
                    if(mode == "1" || mode == "2"){  //原来选择，则不选择
                        setCheckBoxMode.call(loader,checkboxObj,3);
                    }else{  //原来不选择，则选择
                        setCheckBoxMode.call(loader,checkboxObj,1);
                    }
                }else if(flag1 == 2){
                    rowTemp = rowObj;
                    while(true){
                        var checkboxObj = getCheckboxByRow(rowTemp);
                        nextRowTemp = rowTemp.nextSibling;
                        if(mode == "1" || mode == "2"){  //原来选择，则不选择
                            //if(rowTemp.getAttribute("loaded") == "0"){  //子节点没有加载
                                rowTemp.removeAttribute("chckFlg");
                            //}
                            if(checkboxObj != null){
                                setCheckBoxMode.call(loader,checkboxObj,3,true);
                                checkboxObj.checked = false;
                            }
                        }else{
                            //if(rowTemp.getAttribute("loaded") == "0"){  //子节点没有加载
                                rowTemp.setAttribute("chckFlg",1);  //有了这个标识，则加载下级节点时会自动checked
                            //}
                            if(checkboxObj != null){
                                if(checkboxObj.getAttribute("mode") == "3" || checkboxObj.getAttribute("mode") == null){
                                    setCheckBoxMode.call(loader,checkboxObj,1,true);
                                    checkboxObj.checked = true;
                                }
                            }
                        }
                        if(nextRowTemp == null || (parseInt(nextRowTemp.getAttribute("layer")) <= parseInt(rowObj.getAttribute("layer")))){
                            break;
                        }else{
                            rowTemp = nextRowTemp;
                        }
                    }
                }else if(flag1 == 3){
                    rowTemp = rowObj;
                    while(true){
                        var checkboxObj = getCheckboxByRow(rowTemp);
                        nextRowTemp = rowTemp.nextSibling;
                        if(checkboxObj != null){
                            if(rowTemp == rowObj){
                                if(mode == "1" || mode == "2"){  //原来选择，则不选择
                                    //if(rowObj.getAttribute("loaded") == "0"){
                                        rowTemp.removeAttribute("chckFlg");
                                    //}
                                    setCheckBoxMode.call(loader,checkboxObj,3,true);
                                    checkboxObj.checked = false;
                                }else{
                                    //if(rowObj.getAttribute("loaded") == "0"){
                                        rowTemp.setAttribute("chckFlg",2);
                                    //}
                                    if(checkboxObj.getAttribute("mode") == "3" || checkboxObj.getAttribute("mode") == null){
                                        setCheckBoxMode.call(loader,checkboxObj,1,true);
                                        checkboxObj.checked = true;
                                    }
                                }
                            }else if(mode == "1" || mode == "2"){  //原来选择，则不选择
                                if(parseInt(rowTemp.getAttribute("layer")) == parseInt(rowObj.getAttribute("layer")) + 1){
                                    setCheckBoxMode.call(loader,checkboxObj,3,true);
                                    checkboxObj.checked = false;
                                }
                            }else{
                                if(parseInt(rowTemp.getAttribute("layer")) == parseInt(rowObj.getAttribute("layer")) + 1){
                                    if(checkboxObj.getAttribute("mode") == "3" || checkboxObj.getAttribute("mode") == null){
                                        setCheckBoxMode.call(loader,checkboxObj,1,true);
                                        checkboxObj.checked = true;
                                    }
                                }
                            }
                        }
                        if(nextRowTemp == null || (parseInt(nextRowTemp.getAttribute("layer")) == parseInt(rowObj.getAttribute("layer")))){
                            break;
                        }else{
                            rowTemp = nextRowTemp;
                        }
                    }
                }
            }
        };
        
        /**
          * 全选或全清checkbox
          * flag true:全选 ,false:全清
          */
        var setAllCheckBoxMode = function(flag){
            var inputObjs = treeDiv.getElementsByTagName("input");
            if(inputObjs == null){
                return null;
            }
            
            if(flag){  //全选
                for(var i=0;i<inputObjs.length;i++){
                    if(inputObjs[i].getAttribute("type") == "checkbox"){
						//if(inputObjs[i].parentNode.parentNode.getAttribute("loaded") == "0"){  //子节点没有加载
                            inputObjs[i].parentNode.parentNode.setAttribute("chckFlg",1);  //有了这个标识，则加载下级节点时会自动checked
                        //}
						if(inputObjs[i].getAttribute("mode") != "1" && inputObjs[i].getAttribute("mode") != "2"){
                            setCheckBoxMode.call(loader,inputObjs[i],1);
						}
                    }
                }
            }else{  //全清
                for(var i=0;i<inputObjs.length;i++){
                    if(inputObjs[i].getAttribute("type") == "checkbox"){
                        //if(inputObjs[i].parentNode.parentNode.getAttribute("loaded") == "0"){  //子节点没有加载
                            inputObjs[i].parentNode.parentNode.removeAttribute("chckFlg");  //有了这个标识，则加载下级节点时会自动checked
                        //}
						setCheckBoxMode.call(loader,inputObjs[i],3);
                    }
                }
            }
        };
        
        var nodeToRowId = function(nodeId){  //将div的标识的后面加上节点的id
            return treeDivId + nodeId;
        };
        
        var rowToNodeId = function(rowId){  //将节点的id去掉后面的div标识
            return rowId.substring(treeDivId.length,rowId.length);
        };
        
        //字符转换
        var dataFormat = function(str){
            if(str == null){
                return str;
            }else{
                str = str.replace(/&lt;/g,"<");
                str = str.replace(/&gt;/g,">");
                str = str.replace(/&amp;/g,"&");
                str = str.replace(/&quot;/g,"\\");
                str = str.replace(/&nbsp;/g," ");
                return str;
            }
        };
        /*********************************************/
		
		//用于内置菜单项的几个函数
        /**
          * 选择所有子节点-用于内置菜单项
          */
        this.selectAllChildren = function(obj){
            setCheckboxByKey.call(loader,obj,2);
            if(loader.isShiftLoadAllChildren){
                loadAllChildrenAgain.call(loader,obj);
                changeExpandedState.call(loader,obj);  //变换折叠、展开图标
            }
        };
        
        /**
          * 选择直接子节点-用于内置菜单项
          */
        this.selectDirChildren = function(obj){
            setCheckboxByKey.call(loader,obj,3);
            if(loader.isCtrlLoadAllDirChildren){
                loadDirChildrenFromPage.call(loader,obj);
            }
        };
        
        /**
          * 全选checkbox-用于内置菜单项
          */
        this.selectAllCheckBox = function(obj){
            setAllCheckBoxMode.call(loader,true);
        };
        
        /**
          * 全清checkbox-用于内置菜单项
          */
        this.clearAllCheckBox = function(obj){
            setAllCheckBoxMode.call(loader,false);
        };
        
        /**
          * 删除节点-用于内置菜单项
          */
        this.delNode = function(rowObj){
            var isDelAllChildren = window.confirm("是否删除所有下级节点？");
            this.delSelectedNode(isDelAllChildren,rowObj);
        };                
        
        
        /***函数部分：对外接口***/
        
        this.attachEvent = function(sevent,funname){  //通过接口函数将自定义的函数跟相应的事件进行绑定
            events[sevent] = funname;
        };
        
        this.detachEvent = function(sevent){  //通过接口函数取消自定义的函数跟相应的事件的绑定
            events[sevent] = null;
        };
        
        this.setNodeTextStyle = function(nodeid,stylecode){  //动态的指定某节点的文字样式
            var rowObj = $(nodeToRowId(nodeid));
            if(rowObj == null){
                return false;
            }else{
                try{
                    var code = null;
                    var labelTemp = rowObj.getElementsByTagName("label")[0];
                    if(rowObj.getAttribute("initStyle") == null){
                        if(selectedNode == rowObj){
                            rowObj.setAttribute("initStyle",selectedNodeStyle);
                        }else{
                            var initStyle = $gstyle(labelTemp);
                            rowObj.setAttribute("initStyle",initStyle);
                        }
                    }
                    $sstyle(labelTemp,toChangeNull($gstyle(labelTemp)) + ";" + stylecode);
                    if(selectedNode == rowObj){  //如果动态指定样式的节点是当前被选择节点，那么要给selectedNodeStyle加上增加的样式，便于失去选择时，仍有该样式
                        selectedNodeStyle = selectedNodeStyle + ";" + stylecode + ";";
                    }
                    return true;
                }catch(exception){
                    return false;
                }
            }
        };
        
        this.resumeNodeTextStyle = function(nodeId){  //将节点的样式恢复到初始化时的样式
            var rowObj = $(nodeToRowId(nodeId));
            var labelInitStyle = rowObj.getAttribute("initStyle");
            if(rowObj == null || labelInitStyle == null){  //该节点不存在或该节点样式没有变化
                return;
            }
            var labelTemp = rowObj.getElementsByTagName("label")[0];
            var code = labelInitStyle;
            if(selectedNode == rowObj){
                selectedNodeStyle = labelInitStyle;  //"当前别选择节点样式"恢复节点初始样式
                code = code + ";" + this.selectedNodeStyleCode;  //被选择节点样式
            }
            $sstyle(labelTemp,code);
        };
        
        this.isDownLoading = function(){//判断当前状态下，是否正在加载数据（javascript不支持多线程）
            return isDownLoading;
        };
        
        this.setNodeIcon = function(nodeid,nodeiconpath){  //动态的为指定的节点定制任意路径下的节点图标
            var rowObj = $(nodeToRowId(nodeid));
            
            if(rowObj == null){
                return false;
            }
            
            try{
                var imgs = rowObj.childNodes[0].getElementsByTagName("img");
                var nodeIcon = imgs[imgs.length-1];
                nodeIcon.setAttribute("src",nodeiconpath);
                return true;
            }catch(exception){
                return false;
            }
        };
        
        this.setNodeIconAlpha = function(nodeid,alphavalue){  //动态的指定节点图标的alpha值
            var rowObj = $(nodeToRowId(nodeid));
            
            if(rowObj == null){
                return false;
            }
            
            var alphaValue = 50;
            if(alphavalue != null){
                alphaValue = alphavalue;
            }
            try{
                var imgs = rowObj.childNodes[0].getElementsByTagName("img");
                var nodeIcon = imgs[imgs.length-1];
                
                if(document.uniqueID){
                    nodeIcon.style.filter = "alpha(opacity=" + alphaValue + ")";
                }else{
                    var styleCode = toChangeNull(nodeIcon.getAttribute("style")) + ";" + "filter:alpha(opacity=" + alphaValue + ");-moz-opacity:" + alphaValue/100 + ";";
                    nodeIcon.setAttribute("style",styleCode);
                }
                
                return true;
            }catch(exception){
                return false;
            }
        };
        
        this.getIsOpened = function(nodeid){  //返回某一节点是否被展开
            var rowObj = $(nodeToRowId(nodeid));
            
            if(rowObj == null){
                return null;
            }
            
            var flag = rowObj.getAttribute("expanded");
            
            if(flag != null){
                if(flag == "1"){
                    return true;
                }else if(flag == "0"){
                    return false;
                }
            }
        };
        
        this.getIsContainer = function(nodeid){  //返回某一节点是否为容器节点
            var rowObj = $(nodeToRowId(nodeid));
            
            if(rowObj == null){
                return null;
            }
            
            var flag = rowObj.getAttribute("container");
            
            if(flag != null){
                if(flag == "1"){
                    return true;
                }else if(flag == "0"){
                    return false;
                }
            }
        };
        
        this.setCheckState = function(nodeid,state,isall){  //设置某一节点的checkbox的选择状态,如果isall为true，则将所有具有该id的节点checkbox都设成该状态
            var rowObj = $(nodeToRowId(nodeid));
            if(rowObj == null){
                return;
            }
            
            var checkboxObj = getCheckboxByRow(rowObj);
            if(checkboxObj != null){
                setCheckBoxMode.call(loader,checkboxObj,state);
            }
            
            if(isall != null && isall){  //勾选所有具有相同id的节点checkbox
                rowObj = rowObj.nextSibling;
                while(rowObj != null){
                    if(rowToNodeId(rowObj.getAttribute("id")) == nodeid){
	                    checkboxObj = getCheckboxByRow(rowObj);
			            if(checkboxObj != null){
			                setCheckBoxMode.call(loader,checkboxObj,state);
			            }
                    }
                    rowObj = rowObj.nextSibling;
                }
            }
        };
        
        this.getCheckStateByNode = function(nodeid){  //返回某一节点的checkbox当前状态 
            var rowObj = $(nodeToRowId(nodeid));
            if(rowObj == null){
                return null;
            }
            if(!this.isShowCheckbox){  //不是复选模式，返回null
                return null;
            }
            
            var checkboxObj = getCheckboxByRow(rowObj);
            if(checkboxObj != null){
                return checkboxObj.getAttribute("mode");
            }
        };
        
        this.getSelectedNode = function(){  //返回当前被选择的节点的对象
            if(selectedNode == null){
                return null;
            }else{
                return rowToTreeNode.call(loader,selectedNode);
            }
        };
		
		this.getTreeNode = function(rowObj){  //根据树形中的行返回相应的TreeNode对象
			return rowToTreeNode.call(loader,rowObj);
		};
        
        this.getFirstRootNode = function(){  //返回第一个根节点
            var rowObjs = treeDiv.getElementsByTagName("tr");
            if(rowObjs.length > 1){  //存在节点
	            var firstRowObj = treeDiv.getElementsByTagName("tr")[1];
	            if(firstRowObj != null){
	                return rowToTreeNode.call(loader,firstRowObj);
	            }
            }else{
                return null;
            }
        };
        
        this.getShowNodeNum = function(){  //返回当前树形中可见的节点的个数
            var rowObjs = treeDiv.getElementsByTagName("tr");
            var count = 0;
            for(var i=1;rowObjs!=null&&i<rowObjs.length;i++){
                if(rowObjs[i].style.display == ""){
                    count++;
                }
            }
            return count;
        };
        
        this.getNextNeighbor = function(nodeid,issamelayer){  //得到具有nodeId标识的节点相邻的下一个节点
            var rowObj = $(nodeToRowId(nodeid));
            if(rowObj == null){
                return null;
            }
            
            var nextRowObj = rowObj.nextSibling;
            if(nextRowObj == null){
                return null;
            }
            
            if(issamelayer){  //同层节点
                if(nextRowObj.getAttribute("layer") == rowObj.getAttribute("layer")){
                    return rowToTreeNode.call(loader,nextRowObj);
                }else if(parseInt(nextRowObj.getAttribute("layer")) > parseInt(rowObj.getAttribute("layer"))){
                    while(true){
                        nextRowObj = nextRowObj.nextSibling;
                        if(nextRowObj == null){
                            return null;
                        }else if(nextRowObj.getAttribute("layer") == rowObj.getAttribute("layer")){
                            return rowToTreeNode.call(loader,nextRowObj);
                        }
                    }
                }else{
                    return null;
                }
            }else{
                return rowToTreeNode.call(loader,nextRowObj);
            }
        };
        
        this.getPreviousNeighbor = function(nodeid,issamelayer){  //得到具有nodeId标识的节点相邻的上一个节点
            var rowObj = $(nodeToRowId(nodeid));
            if(rowObj == null){
                return null;
            }
            
            var previousRowObj = rowObj.previousSibling;
            if(previousRowObj == null || previousRowObj.previousSibling == null){  //表头行不是节点行
                return null;
            }
            
            if(issamelayer){  //同层节点
                if(previousRowObj.getAttribute("layer") == rowObj.getAttribute("layer")){
                    return rowToTreeNode.call(loader,previousRowObj);
                }else if(parseInt(previousRowObj.getAttribute("layer")) > parseInt(rowObj.getAttribute("layer"))){
                    while(true){
                        previousRowObj = previousRowObj.previousSibling;
                        if(previousRowObj.getAttribute("layer") == rowObj.getAttribute("layer")){
                            return rowToTreeNode.call(loader,previousRowObj);
                        }
                    }
                }else{
                    return null;
                }
            }else{
                return rowToTreeNode.call(loader,previousRowObj);
            }
        };
        
        this.getParentById = function(nodeid){  //得到具有nodeId标识的节点的父节点对象
            var rowObj = $(nodeToRowId(nodeid));
            if(rowObj == null){
                return null;
            }
            
            var parentRow = getParentRow(rowObj);
            if(parentRow == null){
                return null;
            }else{
                return rowToTreeNode.call(loader,parentRow);
            }
        };
        
        this.getNodeById = function(nodeid){  //得到具有nodeId标识的节点的脚本对象
            var rowObj = $(nodeToRowId(nodeid));
            if(rowObj == null){
                return null;
            }
            
            return rowToTreeNode.call(loader,rowObj);
        };
        
        this.refreshSelectedNodeChildren = function(rowobj){  //重新刷新当前被选择的节点的子节点列表
            if(this.readyState != "complete" && this.readyState != "init"){
                setTimeout(function(){loader.refreshSelectedNodeChildren(rowobj);},1000);
                return;
            }
            
            this.readyState = "begin";
            
            var rowObj = null;
			if(rowobj == null){
				rowObj = selectedNode;
			}else if(rowobj instanceof TreeNode){
			    if(rowobj.nodeId != null){
			        rowObj = $(nodeToRowId(rowobj.nodeId));
			        if(rowObj == null){
			            rowObj = selectedNode;
			        }
			    }
			}else{
				rowObj = rowobj;
		    }
			
            if(rowObj == null){
                return false;
            }
            
            refresh = 1;  //记录当前刷新状态
            if(rowObj.getAttribute("loaded") == "1"){
                removeChildrenByCount(rowObj);
                rowObj.setAttribute("expanded",0);
                rowObj.setAttribute("loaded",0);
                clickExpandedIcon.call(loader,rowObj);
                return true;
            }else{
                clickExpandedIcon.call(loader,rowObj);
            }
        };
        
        this.refreshSelectedNode = function(rowobj){  //重新刷新当前被选择的节点所在的节点列表
            if(this.readyState != "complete" && this.readyState != "init"){
                setTimeout(function(){loader.refreshSelectedNode(rowobj);},1000);
                return;
            }
            
            this.readyState = "begin";
            
		    var rowObj = null;
			if(rowobj == null){
				rowObj = selectedNode;
			}else if(rowobj instanceof TreeNode){
			    if(rowobj.nodeId != null){
			        rowObj = $(nodeToRowId(rowobj.nodeId));
			        if(rowObj == null){
			            rowObj = selectedNode;
			        }
			    }
			}else{
				rowObj = rowobj;
		    }
			
            if(rowObj == null){
                return false;
            }
            
            refresh = 2;  //记录当前刷新状态
            if(deletedRow == null){  //当deletedRow不为null，即进行了删除节点操作，则refreshRowId已经在删除节点函数中赋过值了
                refreshRowId = rowObj.getAttribute("id");
            }
            refreshRowIndex = rowObj.rowIndex;
            
            if(rowObj.getAttribute("layer") == "1"){  //根节点，则重新加载树
                if(treeDiv != null){
                    var num = treeDiv.childNodes.length;
                    for(var i=0;i<num;i++){
                        treeDiv.removeChild(treeDiv.firstChild);
                    }
                }
                this.createTree();                
            }else{
                var parentRow = getParentRow(rowObj);
                if(parentRow == null){
                    return false;
                }else{
                    if(parentRow.getAttribute("loaded") == "1"){  //已经加载过
                        removeChildrenByCount(parentRow);
                        parentRow.setAttribute("expanded",0);
                        parentRow.setAttribute("loaded",0);
                    }
					
                    clickExpandedIcon.call(loader,parentRow);
                }
            }
        };
        
        this.clickNode = function(nodeid){  //点击节点
            var rowObj = $(nodeToRowId(nodeid));
            if(rowObj == null){
                return false;
            }
            
            $click(rowObj);
            return true;
        };
        
        this.clickExpandedIcon = function(nodeid, flag){  //点击折叠/展开图标,如果flag为false,则当节点已经展开后就不响应这个函数
            var rowObj = $(nodeToRowId(nodeid));
            if(rowObj == null){
                return false;
            }
            if(!(flag != null && !flag && rowObj.getAttribute("expanded") == "1")){
                clickExpandedIcon.call(loader,rowObj);
            }
        };
        
        this.locateNode = function(nodepath){  //定位到某节点
            var nodePath = nodepath;
            if(nodePath != null){
                if(nodePath instanceof Array){
                    locateSomeNode(nodepath,0);
                }else if(typeof(nodePath) == "string"){
                    var pathArray = nodePath.split(";");
                    locateSomeNode(pathArray,0);
                }else{
                    alert("节点标识路径格式不正确!");
                }
            }else{
                alert("节点标识路径格式不正确!");
            }
            
        };
        
        this.getMenu = function(){  //返回树形中的一级菜单
            return menuFirst;
        };
        
        this.setMenu = function(menuObj){  //设置树形中的一级菜单
            if(menuObj != null && menuObj instanceof Menu){
                menuFirst = menuObj;
            }
        };
        
        this.delSelectedNode = function(isdelallchildren,rowobj){  //Ajax 删除被选择的节点 rowobj是后来加的，用于内置菜单项
            var rowObj = null;
			
		    if(rowobj != null){  //内置菜单项“删除节点”会传入一个行对象
				rowObj = rowobj;
			}else{
                if(selectedNode == null){
                    return null;
                }else{
					rowObj = selectedNode;
				}
			}
			deletedRow = rowObj;  //给这个公共变量赋值
			
            if(this.readyState != "complete" && this.readyState != "init"){
                alert("正在等待服务器端数据......\n请稍候进行操作!");
                //setTimeout(function(){loader.delSelectedNode(isdelallchildren,deletedRow);},200);
                return;
            }
			
			var previousSameLayerRow = null;
            if(rowObj.previousSibling.previousSibling != null){
                previousSameLayerRow = rowObj.previousSibling
            }
            while(previousSameLayerRow != null && previousSameLayerRow.previousSibling != null){
                var layerTemp1 = parseInt(previousSameLayerRow.getAttribute("layer"));
                var layerTemp2 = parseInt(rowObj.getAttribute("layer"));
                if(layerTemp1 < layerTemp2 || layerTemp1 == layerTemp2){
                    refreshRowId = previousSameLayerRow.getAttribute("id");
                    break;
                }else{
                    previousSameLayerRow = previousSameLayerRow.previousSibling;
                }
            }
			
			//为请求服务器做准备
            var id = rowObj.getAttribute("id");
            if(id == null){
                return null;
            }else{
                id = rowToNodeId(id);
            }
            
            var parentRow = getParentRow(rowObj);
            var parentId = treedivid;
            if(parentRow != null){
                parentId = rowToNodeId(parentRow.getAttribute("id"));
            }
            
            
            var queryArray = null; 
            var dealType = null;  //服务器端的操作标志
            var nodeId = null;  //节点标识
            var parentNodeId = null;  //父节点标识
            var webTreeIntfInstId = null;  //用户定义的WebTreeIntf的接口实例的标识
            var isDelAll = null; 
            
            queryArray = new Array();
            dealType = new Array("dealType","5");
            nodeId = new Array("nodeId",id);
            parentNodeId = new Array("parentId",parentId);
            webTreeIntfInstId = new Array("webTreeIntfInstId",this.webTreeIntfInstId);
            if(isdelallchildren){
                isDelAll = new Array("isDelAll","1");
            }else{
                isDelAll = new Array("isDelAll","0");
            }
                    
            queryArray.push(dealType,nodeId,parentNodeId,webTreeIntfInstId,isDelAll);
            queryString = this.createQueryString(queryArray);

            this.doRequestUsingPost.call(loader,5,id);  //开始向服务器提交数据
        };
        
        this.insertNode = function(nodeObj){  //Ajax 增加节点（当前被选择的节点为该节点的父节点）
            if(selectedNode == null || nodeObj == null || !(nodeObj instanceof TreeNode)){
                return null;
            }
            if(this.readyState != "complete" && this.readyState != "init"){
                alert("正在等待服务器端数据......\n请稍候进行操作!");
                //setTimeout(function(){loader.insertNode(nodeObj);},200);
                return;
            }
            
            insertNodeId = nodeToRowId(nodeObj.nodeId);  //记录要增加节点的id(前面加容器div的id)
            
            var queryArray        = null; 
            var dealType          = null;  //服务器端的操作标志
            var nodeName          = null;  //节点名称
            var attrs             = null;  //附加信息
            var parentNodeId      = null;  //父节点标识
            var webTreeIntfInstId = null;  //用户定义的WebTreeIntf的接口实例的标识
            
            queryArray = new Array();
            dealType = new Array("dealType","4");
            nodeName = new Array("nodeName",escape(nodeObj.getNodeName()).replace(/%/g,'yuankuang'));//编码
            parentNodeId = new Array("parentId",rowToNodeId(selectedNode.getAttribute("id")));
            webTreeIntfInstId = new Array("webTreeIntfInstId",this.webTreeIntfInstId);

            var attrTemp = nodeObj.getAttributes();
            var strTemp = "";
            for(var i=0;i<attrTemp.length;i++){
                strTemp = strTemp + escape(attrTemp[i][0]).replace(/%/g,'yuankuang') + "," + escape(attrTemp[i][1]).replace(/%/g,'yuankuang') + ";";
            }
            attrs = new Array("attrs",strTemp);
            
            queryArray.push(dealType,nodeName,attrs,parentNodeId,webTreeIntfInstId);
            queryString = this.createQueryString(queryArray);
            
            this.doRequestUsingPost.call(loader,4,"");  //开始向服务器提交数据
        };
        
        this.searchNode = function(key){  //未测试 Ajax 传入要搜索的节点的相关信息，并开始搜索
            if(key == null){
                return;
            }
            if(this.readyState != "complete" && this.readyState != "init"){
                alert("正在等待服务器端数据......\n请稍候进行操作!");
                return;
            }
            var queryArray        = new Array();
            var dealType          = new Array("dealType","6");  //服务器端的操作标志
            var key               = new Array("key",key);
            var webTreeIntfInstId = new Array("webTreeIntfInstId",this.webTreeIntfInstId);  //用户定义的WebTreeIntf的接口实例的标识
            
            queryArray.push(dealType,key,webTreeIntfInstId);
            queryString = this.createQueryString(queryArray);
            
            this.doRequestUsingPost.call(loader,6,"");  //开始向服务器提交数据
            
        };
        
        this.searchNextNode = function(){  //搜索下一个节点
            if(searchResult.hasNextNode()){
                var nextPath = searchResult.getNextNodePath();
                if(nextPath == ""){
                    this.searchNextNode();
                    return;
                }else{
                    locateSomeNode(nextPath,0);  //定位
                }
            }else{
                alert("没有满足条件的下一个节点！");
            }
        };
        
        this.getCheckedNodeIds = function(checkmode){  //未完成8 返回复选模式下树中被选择的节点的标识列表
            if(!this.isShowCheckbox){
                return;
            }
            
            if(checkmode == null){  //如果开发者没有传递参数，默认为是"选择未展开节点的全部子节点"
                checkmode = 2;
            }
            
            var inputObjs = treeDiv.getElementsByTagName("input");
            if(inputObjs == null){
                return null;
            }
           
            checkedBoxes = new Array();  //一个公共变量
            if(checkmode == 0 || checkmode == "0"){  //不选择未展开（子节点没有被加载过）节点的任何子节点
                for(var i=0;i<inputObjs.length;i++){
                    if(inputObjs[i].getAttribute("type") == "checkbox" && inputObjs[i].checked){
                        checkedBoxes.push(rowToNodeId(inputObjs[i].parentNode.parentNode.getAttribute("id")));
                    }
                }
                
                var evFunc = events["onGetCheckedComplete"];
                if(evFunc != null){
                    evFunc(checkedBoxes);  //向用户定义的函数里传入节点id的数组
                }
                return checkedBoxes;  //如果只选择展开的节点，则可以直接返回
            }else{
                if(this.readyState != "complete" && this.readyState != "init"){
                    alert("正在等待服务器端数据......\n请稍候进行操作!");
                    return;
                }
                var noLoadedIds = "";
                for(var i=0;i<inputObjs.length;i++){
                    var rowObj = inputObjs[i].parentNode.parentNode;
                    if(inputObjs[i].getAttribute("type") == "checkbox" && inputObjs[i].checked){
                        checkedBoxes.push(rowToNodeId(inputObjs[i].parentNode.parentNode.getAttribute("id")));
                        if(rowObj.getAttribute("loaded") == "0" && rowObj.getAttribute("container") == "1"){
                            noLoadedIds = noLoadedIds + rowToNodeId(rowObj.getAttribute("id")) + ";";
                        }
                    }
                }
                
                var queryArray        = new Array();
                var dealType          = new Array("dealType","3");  //服务器端的操作标志
                var ids               = new Array("ids",noLoadedIds);
                var webTreeIntfInstId = new Array("webTreeIntfInstId",this.webTreeIntfInstId);  //用户定义的WebTreeIntf的接口实例的标识
                var checkMode         = null;  //处理未展开节点的模式  
                if(checkmode == 1 || checkmode == "1"){  //选择未展开节点的直接子节点
                    checkMode         = new Array("checkMode","1");
                }else if(checkmode == 2 || checkmode == "2"){  //选择未展开节点的全部子节点
                    checkMode         = new Array("checkMode","2");
                }
                
                queryArray.push(dealType,ids,checkMode,webTreeIntfInstId);
                queryString = this.createQueryString(queryArray);
           
                if(checkmode == 1 || checkmode == "1"){
                    this.doRequestUsingPost.call(loader,3,"");  //开始向服务器提交数据
                }else if(checkmode == 2 || checkmode == "2"){
                    this.doRequestUsingPost.call(loader,3,"");
                }
            }
        };
        
        /**
         * 清空所有还未加载的节点的checked状态
         */
        this.clearUnLoadNodeCheckBoxMode = function(){
            var inputObjs = treeDiv.getElementsByTagName("input");
            if(inputObjs == null){
                return null;
            }
            //将所有没有加载节点的节点将要处理的内容给去掉--全清
            for(var i=0;i<inputObjs.length;i++){
                if(inputObjs[i].getAttribute("type") == "checkbox"){
                     if(inputObjs[i].parentNode.parentNode.getAttribute("loaded") == "0"){  //子节点没有加载
                         inputObjs[i].parentNode.parentNode.removeAttribute("chckFlg");  //有了这个标识，则加载下级节点时会自动checked
                     }
                     inputObjs[i].removeAttribute("mode");
                }
            }
        };
        
         /**反选操作
		 * @author wangyoufa
		 */
        this.setCheckedContrary = function(){
            var inputObjs = treeDiv.getElementsByTagName("input");
            if(inputObjs == null){
                return null;
            }
            checkedBoxes = new Array();  //一个公共变量
            for(var i=0;i<inputObjs.length;i++){
                if(inputObjs[i].getAttribute("type") == "checkbox"){
                	inputObjs[i].checked = !inputObjs[i].checked;
           		}
            }
        };
        
        //获得没有勾选节点的guid
        this.getNoCheckedNodeIds = function(checkmode){  //未完成8 返回复选模式下树中未被选择的节点的标识列表
            if(!this.isShowCheckbox){
                return;
            }
            
            if(checkmode == null){  //如果开发者没有传递参数，默认为是"选择展开节点的全部为勾选子节点"
                checkmode = 0;
            }
            
            var inputObjs = treeDiv.getElementsByTagName("input");
            if(inputObjs == null){
                return null;
            }
           
            checkedBoxes = new Array();  //一个公共变量
            if(checkmode == 0 || checkmode == "0"){  //不选择未展开（子节点没有被加载过）节点的任何子节点
                for(var i=0;i<inputObjs.length;i++){
                    if(inputObjs[i].getAttribute("type") == "checkbox" && !inputObjs[i].checked){
                        checkedBoxes.push(rowToNodeId(inputObjs[i].parentNode.parentNode.getAttribute("id")));
                    }
                }
                
                var evFunc = events["onGetCheckedComplete"];
                if(evFunc != null){
                    evFunc(checkedBoxes);  //向用户定义的函数里传入节点id的数组
                }
                return checkedBoxes;  //如果只选择展开的节点，则可以直接返回
            }
        };
         /**设置节点状态,将当前选择的节点状态置为自己需要的状态
		 * @author wangyoufa
		 * @param isClear 是否除了节点以外，其他节点都不选中
		 * @param checktype 0这些节点不勾选；1这些节点勾选
		 * @param nodeArray 需要操作的节点
		 */
        this.setNodeCheckedStatus = function(isClear,checktype,nodeArray){
			var myNodeArray = nodeArray;
            if(myNodeArray == null){//操作的节点为空则设置一个空的处理
	            myNodeArray = new Array();
	        }
            var inputObjs = treeDiv.getElementsByTagName("input");
            if(inputObjs == null){
                return null;
            }
           
            if(checktype == null){  //如果开发者没有传递参数，默认为是"将这些节点勾选上"
                checktype = 1;
            }
            checkedBoxes = new Array();  //一个公共变量
            var isChecked = false;
            if(checktype == 1 || checktype == "1"){  //不选择未展开（子节点没有被加载过）节点的任何子节点
            	isChecked = true;
            }
            var nodeId = "";
            var myNodeId = "";
            var basicStyle = "";
            for(var i=0;i<inputObjs.length;i++){
                if(inputObjs[i].getAttribute("type") == "checkbox"){
                	if(isClear == "1" ){
                		inputObjs[i].checked = false;
                	}
                	nodeId = rowToNodeId(inputObjs[i].parentNode.parentNode.getAttribute("id"));
	                for(var j = 0 ; j < myNodeArray.length ; j++){
	                	myNodeId = myNodeArray[j];
	                	if(myNodeId != "" && nodeId == myNodeId){
	                		inputObjs[i].checked = isChecked;
	                		if(isChecked){
				                inputObjs[i].setAttribute("mode",1);
				                inputObjs[i].setAttribute("style",basicStyle);
	                		}
	                		break;
	                	}
	                }
           		}
            }
        };
         this.getDirChildNodes = function(nodeid, flag){  //得到具有nodeId标识的节点的直接子节点标识列表,flag为false则取浏览器端已加载的直接子节点
            if(nodeid == null){  //如果nodeId为null则默认取根节点
                nodeid = "";
            }
            if(flag != null && !flag){  //取浏览器端已加载的直接子节点
                var rowObj = $(nodeToRowId(nodeid));
                if(rowObj == null){
                    return null;
                }else{
                    var dirChildren = new Array();
                    var nextDirChild = rowObj.nextSibling;
                    var layer = parseInt(rowObj.getAttribute("layer"));
                    while(nextDirChild != null){
                        if(layer == parseInt(nextDirChild.getAttribute("layer")) - 1 && nextDirChild.getAttribute("next") != "1"){  //直接子节点,分页节点不算
                            dirChildren.push(rowToNodeId(nextDirChild.getAttribute("id")));
                        }else if(layer >= parseInt(nextDirChild.getAttribute("layer"))){
                            break;
                        }
                        nextDirChild = nextDirChild.nextSibling;
                    }
                    return dirChildren;
                }
            }else{  //到服务器端去取
	            var queryArray = new Array();
	            var nodeId = new Array("nodeId",nodeid);
	            var dealType = new Array("dealType","7");  //服务器端的操作标志
	            var webTreeIntfInstId = new Array("webTreeIntfInstId",this.webTreeIntfInstId);  //用户定义的WebTreeIntf的接口实例的标识
	            queryArray.push(dealType,nodeId,webTreeIntfInstId);
	            queryString = this.createQueryString(queryArray);
	            this.doRequestUsingPost.call(loader,7,"");
            }
        };
        
        this.getAllChildNodes = function(nodeid){  //得到具有nodeId标识的节点的全部子节点标识列表
            if(nodeid == null){  //如果nodeId为null则默认取根节点
                nodeid = "";
            }
            
            var queryArray = new Array();
            var nodeId = new Array("nodeId",nodeid);
            var dealType = new Array("dealType","8");  //服务器端的操作标志
            var webTreeIntfInstId = new Array("webTreeIntfInstId",this.webTreeIntfInstId);  //用户定义的WebTreeIntf的接口实例的标识
            queryArray.push(dealType,nodeId,webTreeIntfInstId);
            queryString = this.createQueryString(queryArray);
            this.doRequestUsingPost.call(loader,8,"");
        };
        
        this.getLodedNodeIds = function(){  //返回已经加载过的节点的标识列表
            var nodeIds = new Array();
            var rowObjs = treeTable.getElementsByTagName("TR");
            if(rowObjs != null && rowObjs.length > 1){
                for(var i=1;i<rowObjs.length;i++){
                    nodeIds.push(rowToNodeId(rowObjs[i].getAttribute("id")));
                }
            }
            return nodeIds;
        };
        
        this.getRefreshState = function(){  //返回当前刷新状态
            return refresh;
        };
        
        this.hideWaitingImg = function(hideFlag){  //隐藏等待图片
            if(waitingImg != null){
                if(hideFlag != null){
                    waitingImg.style.display = hideFlag;
                }else{
                    waitingImg.style.display = "none";
                }
            }
        };
        
        this.getWaitingImg = function(){
            return waitingImg;
        };
        
        this.setCtrlKey = function(flag){  //设置ctrlKey
            if(flag != null){
                if(flag){
                    ctrlKey = true;
                }else{
                    ctrlKey = false;
                }
            }
        };
        
        this.setShiftKey = function(flag){  //设置shiftKey
            if(flag != null){
                if(flag){
                    shiftKey = true;
                }else{
                    shiftKey = false;
                }
            }
        };
		
    };//end Tree主类
    

/**********************************TreeNode类************************************/
    
    function TreeNode(nodeid){//start TreeNode主类
        this.nodeId = nodeid;   //节点标识
        this.nodeName = null;   //节点名称
        this.attributes = new Array();   //节点的附加属性，二维数组
        this.count = 0;  //用于记录当点击该节点时要折叠或展开的行数
        this.expanded = false;  //节点是否展开，true为展开，false为未展开
        this.container = false;  //是否为容器节点，true是，false否
        this.loaded = false;  //该节点的子节点是否被加载,true是，false否
        this.isFirst = false;  //该节点在所在层是否是第一个节点,true是，false否
        this.isEnd = false;  //该节点在所在层是否是最后一个节点,true是，false否

        this.checkMode = null;  //该节点复选模式下的选择状态,1全选,2半选,3未选,如果为null则不存在复选框

        this.currentIconPath = null;  //当前状态下节点图标路径
        this.styleCode = null;  //当前状态下节点的样式代码
        this.styleClass = "WebTreeCellLabel";  //节点的样式选择器名
        
        
        
        //分页节点特有属性
        this.isNext = false;  //是否为分页节点，true为是，否则不是
        this.pNum = 1;  //当前页码
        
        
        
        /***函数部分***/
        this.getNodeId = function(){  //返回节点的id
            return this.nodeId;
        };
    
        this.getNodeName = function(){  //返回节点的名称
            return this.nodeName;
        };
    
        this.getAttribute = function(key){  //根据key返回节点的附加属性
            for(var i=0;i<this.attributes.length;i++){
                if(this.attributes[i][0] == key){
                    return this.attributes[i][1];
                }
            }
        };
        
        this.getAttributes = function(){  //返回节点的附加属性
            return this.attributes;
        };
        
        this.setNodeId = function(nodeid){  //设置节点的id
            this.nodeId = nodeid;
        };
    
        this.setNodeName = function(nodename){  //设置节点的名称
            this.nodeName = nodename;
        };
    
        this.insertAttribute = function(key,value){  //设置节点附加属性
            var arrayTemp = new Array();
            arrayTemp.push(key,value);
            this.attributes.push(arrayTemp);
        };
        
    };//end  TreeNode主类
    
/**********************************MenuItem类***********************************/
    
    function MenuItem(itemid,itemtitle, functionname,itemiconpath){//start MenuItem主类
        this.itemId = itemid;                //菜单项标识
        this.itemTitle = itemtitle;          //菜单项标题
        this.functionName = functionname;    //当点击该菜单项时调用用户自己定义的函数的名称
        this.itemIconPath = itemiconpath;    //菜单项的图标的路径
        
        this.hasSubMenu = false;             //鼠标移到该菜单项出现下级菜单
        this.subMenu = null;                 //该菜单项的子菜单
        this.isDisabled = false;             //该菜单项是否disabled
        this.isSeparator = false;            //该菜单项是否为分隔线
        
        /***函数部分***/
        this.setSubMenu = function(hassubmenu,menuobj){  //设置是否有下级菜单及下级菜单实例
            this.hasSubMenu = hassubmenu;
            if(menuobj instanceof Menu){
                this.subMenu = menuobj;
            }
        };
    
        this.setIsDisabled = function(isdisabled){  //设置该菜单项是否disabled
            this.isDisabled = isdisabled;
        };
    
        this.setIsSeparator = function(isseparator){  //设置该菜单项是否为下划线
            this.isSeparator = isseparator;
        };
        
        this.getItemId = function(){  //返回菜单项标识
            return this.itemId;
        };
        
        this.getItemTitle = function(){  //返回菜单项标题
            return this.itemTitle;
        };
        
        this.getFunctionName = function(){  //返回当点击该菜单项时调用用户自己定义的函数的名称
            return this.functionName;
        };
        
        this.getItemIconPath = function(){  //返回菜单项的图标的路径
            return this.itemIconPath;
        };
        
        this.getHasSubMenu = function(){  //鼠标移到该菜单项出现下级菜单
            return this.hasSubMenu;
        };
        
        this.getSubMenu = function(){  //返回该菜单项的子菜单
            return this.subMenu;
        };
        
        this.getIsDisabled = function(){  //返回该菜单项是否disabled
            return this.isDisabled;
        };
        
        this.getIsSeparator = function(){  //返回该菜单项是否为分隔线
            return this.isSeparator;
        };
    };//end MenuItem主类


/************************************Menu类*************************************/
    
    function Menu(treeobj){//start Menu主类
        var loader = this;
        var layer = 0;                                     //该菜单为几级菜单
        var menuDivIds = [];                               //菜单div的id列表，下标0表示当前菜单div，1为下级菜单……
        var menuItemList = [];                             //该菜单中的菜单项列表
		var treeObj = treeobj;                             //Tree类的实例，用于在菜单中可以调用Tree中的方法
        
        var menuDiv = null;                                //该菜单所在的div
        var menuTable = null;                              //菜单中的table
        var menuTbody = null;                              //菜单中的tbody，主要用于IE
        var menuRow = null;                                //table中的tr
        var menuCell = null;                               //tr中的td
        var menuItemIcon = null;                           //菜单项图标
        var menuItemSubIcon = null;                        //标识是否有下级菜单的图标
        var menuBgIcon = null;                             //菜单的背景图片
        
        this.treeRowId = null;                             //树形中右键选中的节点的id
        this.iconsDirectory = null;                        //菜单中图标的统一路径
        this.menuStyleCode = null;                         //菜单的样式代码
        
		//内置的五个菜单项
        this.menuItem_allChildren = null;                   //选择全部下级
        this.menuItem_directChildren = null;                //选择直接下级
        this.menuItem_selectAll = null;                     //全选
        this.menuItem_clearAll = null;                      //全清
        this.menuItem_deleteNode = null;                    //删除节点
        
        /***内部函数***/
        this.init = function(){
            if(menuDivIds[layer - 1] != null){  //当前菜单的div
                menuDiv = $(menuDivIds[layer - 1]);
                if(menuDiv == null){
                    return;
                }
            }else{
				return;
			}
			
            menuTable = $C("table");
            menuTbody = $C("tbody");
            menuRow = $C("tr");
            menuCell = $C("td");
            menuItemIcon = $C("img");
            menuItemSubIcon = menuItemIcon.cloneNode(true);
            
            menuItemSubIcon.setAttribute("flag",1);
            if(this.menuItemSubIconPath != null){
                menuItemSubIcon.setAttribute("src",this.menuItemSubIconPath);
            }
            
            for(var i=0;i<3;i++){  //1 icon, 2 内容 , 3 标识是否有下级菜单
                menuRow.appendChild(menuCell.cloneNode(true));
            }
            
            menuTable.appendChild(menuTbody);
            
			menuDiv.oncontextmenu = function(){return false;};  //屏蔽右键
			
            if(this.iconsDirectory != null && this.iconsDirectory != ""){  //设置菜单图标的路径
                menuItemSubIcon.setAttribute("src",this.iconsDirectory + "/point.gif");
				//alert(this.iconsDirectory + "/menubg.jpg");
				menuDiv.style.backgroundImage = "url("+this.iconsDirectory + "menubg.jpg"+")";
				menuDiv.style.backgroundPosition = "bottom right";
            }
            
            //这里设置表格、cell等的style的class
            var strClass;
            if(document.uniqueID){
                strClass = "className";
            }else{
                strClass = "class";
            }
            menuDiv.setAttribute(strClass,"WebTreeMenu");
            menuTable.setAttribute(strClass,"WebTreeMenuTable");
            menuCell.setAttribute(strClass,"WebTreeMenuCell");
            
            //单独设置菜单表格的样式代码
            if(this.menuStyleCode != null){
                $sstyle(menuTable,$gstyle(menuTable) + ";" + this.menuStyleCode);
            }

            //初始化五个内置菜单项 
			if(treeObj != null){
                this.menuItem_allChildren = new MenuItem("MENU_DEFAULT_ALLCHILDREN","选择全部下级", selectAllChildren,this.iconsDirectory+"/selectallchild.gif");            //选择全部下级
                this.menuItem_directChildren = new MenuItem("MENU_DEFAULT_DIRECTCHILDREN","选择直接下级", selectDirChildren,this.iconsDirectory+"/selectchild.gif");      //选择直接下级
                this.menuItem_selectAll = new MenuItem("MENU_DEFAULT_SELECTALL","全选", selectAllCheckBox,this.iconsDirectory+"/selectall.gif");                       //全选
                this.menuItem_clearAll = new MenuItem("MENU_DEFAULT_CLEARALL","全清", clearAllCheckBox,this.iconsDirectory+"/clearall.gif");                          //全清
                this.menuItem_deleteNode = new MenuItem("MENU_DEFAULT_DELETENODE","删除节点", delNode,this.iconsDirectory+"/delete.gif");                    //删除节点
			}
        };
        
		
        //为菜单项的row增加事件
        var addEvents = function(rowObj){
            rowObj.onclick = function(event){
                return onMenuItemClick.call(loader,event,rowObj);
            };
            
            rowObj.onmouseover = function(event){
                return onMenuItemMouseOver.call(loader,event,rowObj);
            };
            
            rowObj.onmouseout = function(event){
                return onMenuItemMouseOut.call(loader,event,rowObj);
            };
        };
        
        //点击菜单项
        var onMenuItemClick = function(event,rowObj){
            if(rowObj.getAttribute("isSeparator") == "1" || rowObj.getAttribute("hasSubMenu") == "1"){
                return false;
            }
            
            this.hideAllMenu();
            
            if(rowObj.getAttribute("event") == "1"){
                var menuItem = null;
                rowObjId = rowObj.getAttribute("id");
                for(var i=0;i<menuItemList.length;i++){
                    if(menuItemList[i].itemId == rowObjId){
                        menuItem = menuItemList[i];
                    }
                }
                var func = menuItem.functionName;
                if(func != null){
                    func(treeObj.getTreeNode($(this.treeRowId)));
                }
            }
            return false;
        };
        
        //鼠标移上菜单项
        var onMenuItemMouseOver = function(event,rowObj){
            if(rowObj != null){
                if(rowObj.getAttribute("isSeparator") != "1"){
                    var nextRowObj = rowObj;
                    while(true){
                        nextRowObj = nextRowObj.nextSibling;
                        if(nextRowObj == null){
                            break;
                        }else{
                            nextRowObj.bgColor = "";
                        }
                    }
                    var previousRowObj = rowObj;
                    while(true){
                        previousRowObj = previousRowObj.previousSibling;
                        if(previousRowObj == null){
                            break;
                        }else{
                            previousRowObj.bgColor = "";
                        }
                    }
                
                    rowObj.bgColor = "#7c99e2";  //不是分隔符，移上鼠标,菜单项变为蓝色
                }
                
                var ev = event || window.event;
                var eventSrc = ev.target || ev.srcElement;
                
                if(rowObj.getAttribute("hasSubMenu") == "1"){  //如果有子菜单，则显示子菜单
                    if(layer > 0 && layer < menuDivIds.length){
                        var subMenuId = menuDivIds[layer];  //取得子菜单的div
                        if(subMenuId == null){
                            return false;
                        }
                        
                        var menuItem = null;
                        rowObjId = rowObj.getAttribute("id");
                        for(var i=0;i<menuItemList.length;i++){
                            if(menuItemList[i].itemId == rowObjId){
                                menuItem = menuItemList[i];
                            }
                        }
                        var subMenu = menuItem.subMenu;
                        if(menuItem == null || subMenu == null){
                            return false;
                        }
                      
                        subMenu.setMenuDivIds(menuDivIds);  //这几步很关键,类递归时传递参数
                        subMenu.setLayer(layer+1);
                        subMenu.setTreeRowId(this.treeRowId);
						subMenu.setTree(treeobj);  //后来加的，设置菜单中Tree实例
                        if(this.iconsDirectory != null && this.iconsDirectory != ""){  //设置菜单图标的路径
                            subMenu.iconsDirectory = this.iconsDirectory;
                        }
                        if(this.menuStyleCode != null && this.menuStyleCode != ""){  //设置子菜单的样式代码
                            subMenu.menuStyleCode = this.menuStyleCode;
                        }
                            
					    subMenu.init();
                        subMenu.createMenu();
                            
                        var left = menuDiv.style.left;
                        var top = menuDiv.style.top;
                        var x = parseInt(left.substring(0,left.length-2)) + rowObj.offsetWidth;
                        var y = 0;
                        y = parseInt(top.substring(0,top.length-2)) + rowObj.offsetTop;
                        
                        //if(document.body.clientHeight - y < $(menuDivIds[layer]).offsetHeight){
                        //    y = y - $(menuDivIds[layer]).offsetHeight + rowObj.offsetHeight;
                        //}
                            
                        subMenu.showMenu(x,y);
                    }
                }else{
                    for(var i=layer;i<menuDivIds.length;i++){  //如果没有子菜单，则把子菜单的div隐藏
                        var subMenuDiv = $(menuDivIds[layer]);
                        if(subMenuDiv != null && subMenuDiv.style.display != "none"){
                            subMenuDiv.style.display = "none";
                        }
                    }
                }
            }
        };
        
        //鼠标移出菜单项
        var onMenuItemMouseOut = function(event,rowObj){
            //if(rowObj != null){
            //    rowObj.bgColor = "#ece9d8";
            //}
        };
        
        //将null装换为空字符串
        var toChangeNull = function(data){
            if(data == null){
                return "";
            }else{
                return data;
            }
        };
        
		//五个内置菜单项的关联函数
		//选择直接下级
		var selectDirChildren = function(){
            if(treeObj != null){
				treeObj.selectDirChildren.call(treeObj,$(loader.treeRowId));
			}			
		};
		//选择全部下级
		var selectAllChildren = function(){
			if(treeObj != null){
				treeObj.selectAllChildren.call(treeObj,$(loader.treeRowId));
			}
		};
		//全选
		var selectAllCheckBox = function(){
			if(treeObj != null){
				treeObj.selectAllCheckBox.call(treeObj,$(loader.treeRowId));
			}
		};
		//全清
		var clearAllCheckBox = function(){
			if(treeObj != null){
				treeObj.clearAllCheckBox.call(treeObj,$(loader.treeRowId));
			}
		};
		//删除节点
		var delNode = function(){
			if(treeObj != null){
				treeObj.delNode.call(treeObj,$(loader.treeRowId));
			}
		};
        
        
        /***对外接口函数部分***/
        this.setMenuDivIds = function(menudivids){  //设置菜单div的id，这个div是需要在外面创建好的
            menuDivIds = menudivids;
        };
        
        this.setTreeRowId = function(treerowid){  //设置树形中某节点的id,用于在Menu类中调用
            this.treeRowId = treerowid;
        };
		
		this.setTree = function(treeobj){  //设置菜单中的treeObj属性
			treeObj = treeobj;
		};
        
        this.createMenu = function(){  //开始创建菜单，也就是开始在传进来的div中加菜单项
            if(menuDiv != null){
				while(true){
					if(menuDiv.firstChild != null){
					    menuDiv.removeChild(menuDiv.firstChild);
					}else{
						break;
					}
				}
                    
		        var menuTableTemp = menuTable.cloneNode(true);
                menuDiv.appendChild(menuTableTemp);  //div中加table
                    
                var tObj = null;  //IE下为tbody，FF下为table
                tObj = menuTableTemp.firstChild;  //tbody
                    
                for(var i=0;menuItemList!=null&&i<menuItemList.length;i++){
                    var menuItem = menuItemList[i];
                    var rowObj = menuRow.cloneNode(true);  //一行中有三个单元格
                    tObj.appendChild(rowObj); //将一个菜单项加入table或tbody中
                        
                    rowObj.setAttribute("id",menuItem.itemId);
                        
                    if(menuItem.isSeparator){  //分隔符，设在第二个单元格里
                        var hrObj = $C("hr");
                        for(var j=0;j<2;j++){
                            rowObj.removeChild(rowObj.firstChild);
                        }
                        rowObj.firstChild.setAttribute("colSpan",3); 
                        rowObj.firstChild.appendChild(hrObj);
                        rowObj.setAttribute("isSeparator",1);
                    }else{
                        if(menuItem.itemIconPath != null && menuItem.itemIconPath != ""){  //菜单项图标
                            var icon = menuItemIcon.cloneNode(true);
                            icon.setAttribute("src",menuItem.itemIconPath);
                            rowObj.firstChild.appendChild(icon);
                        }
                            
                        rowObj.firstChild.nextSibling.appendChild(document.createTextNode(menuItem.itemTitle));  //菜单项标题
                            
                        if(menuItem.hasSubMenu){
                            rowObj.firstChild.nextSibling.nextSibling.appendChild(menuItemSubIcon.cloneNode(true));
                            rowObj.setAttribute("hasSubMenu",1);
                        }
                        
                        if(menuItem.functionName != null){
                            rowObj.setAttribute("event",1);
							rowObj.style.cursor = "pointer";  //当鼠标在有函数的菜单项上显示手型
                        }
                    }
                    addEvents(rowObj);
                }
            }
        };
        
        //根据坐标的位置显示菜单
        this.showMenu = function(x,y){
            if(menuDiv != null){
                var rows = menuDiv.getElementsByTagName("tr");
                for(var i=0;rows!=null&&i<rows.length;i++){  //每次显示前先把所有菜单项背景色清空
                    rows[i].bgColor = "";
                }
                
                menuDiv.style.display = "";
                //设置位置
                if(x != null && y != null){
                    var rightEdge = document.body.clientWidth-x;
                    var bottomEdge = document.body.clientHeight-y;
                    if(rightEdge < menuDiv.offsetWidth){  //x位置到浏览器最右边小于div的宽度，则菜单在x左边显示
                        if(layer > 1){  //非一级菜单在上级菜单的左侧显示
                            menuDiv.style.left = document.body.scrollLeft + x - menuDiv.offsetWidth * 2 - 15;
                        }else{  //一级菜单在x的左侧显示
                            menuDiv.style.left = document.body.scrollLeft + x - menuDiv.offsetWidth;
                        }
                    }else{
                        menuDiv.style.left = document.body.scrollLeft + x;
                    }
                    if(bottomEdge < menuDiv.offsetHeight){  //y位置到浏览器最下边小于div的高度，则菜单在y上边显示
                        menuDiv.style.top = document.body.scrollTop + y - menuDiv.offsetHeight;
                    }else{
                        menuDiv.style.top = document.body.scrollTop + y;
                    } 
                }
            }
        };
        
        //隐藏菜单（包括下级菜单）
        this.hideMenu = function(){
            if(menuDivIds != null){
                for(var i=layer-1;i>=0&&i<menuDivIds.length;i++){
                    var menuDiv = $(menuDivIds[i]);
                    if(menuDiv != null && menuDiv.style.display != "none"){
                        menuDiv.style.display = "none";
                    }
                }
            }
        };
        
        //隐藏所有的菜单
        this.hideAllMenu = function(){
            if(menuDivIds != null){
                for(var i=0;i<menuDivIds.length;i++){
                    var menuDiv = $(menuDivIds[i]);
                    if(menuDiv != null && menuDiv.style.display != "none"){
                        menuDiv.style.display = "none";
                    }
                }
            }
        }; 
       
        
       this.setLayer = function(num){
           layer = num;
       }; 
        
        
       /***针对开发者的对外接口函数***/ 
        this.insertMenuItem = function(item){  //向菜单中插入菜单项
			if(item instanceof MenuItem){
                menuItemList[menuItemList.length] = item;
            }
        };
    
        this.getMenuItems = function(){  //返回菜单中的菜单项列表
            return menuItemList;
        };
    
        this.deleteMenuItem = function(itemid){  //删除指定标识的菜单项
            if(itemid!=null && menuItemList!=null && menuItemList.length!=null){
                for(var i=0;i<menuItemList.length;i++){
                    if(menuItemList[i].getItemId() == itemid){
                        menuItemList.splice(i,1);
                    }
                }
            }
        };
        
        this.setMenuItemDisabled = function(itemid,isdisabled){  //将菜单div中的菜单项灰掉
            if(menuDiv!=null){
                var rowObj = $(itemid);
                if(rowObj != null){
                    if(document.uniqueID){
                        rowObj.disabled = true;
                    }else{ }//未完成 FF下tr、td不支持disabled属性
                }
            }
        };    
		
		//插入默认菜单项-选择直接下级
		this.insertMenuItem_SelectDirChildren = function(){
			this.insertMenuItem(this.menuItem_allChildren);
		};
		
		//插入默认菜单项-选择全部下级
		this.insertMenuItem_SelectAllChildren = function(){
			this.insertMenuItem(this.menuItem_directChildren);
		};
		
		//插入默认菜单项-全选
		this.insertMenuItem_SelectAllCheckBox = function(){
			this.insertMenuItem(this.menuItem_selectAll);
		};
		
		//插入默认菜单项-全清
		this.insertMenuItem_ClearAllCheckBox = function(){
			this.insertMenuItem(this.menuItem_clearAll);
		};
		
		//插入默认菜单项-删除节点
		this.insertMenuItem_DelSelectedNode = function(){
			this.insertMenuItem(this.menuItem_deleteNode);
		};
		
		//插入一个分隔线菜单项
		this.insertMenuItem_Separator = function(){
		    var menuItem = new MenuItem();
            menuItem.setIsSeparator(true);  //分隔线
		    this.insertMenuItem(menuItem);
		};
		
    };//end Menu主类
    
    
/********************************SearchResult类*********************************/
    
    function SearchResult(){//start SearchResult主类
        var nodeIdList = null;  //搜索到的节点标识列表
        var index = 0;         //当前定位的节点在nodeIdList中的下标
        
        /***函数部分***/
        this.getNodeIdList = function(){  //返回搜索到的满足搜索条件的节点标识列表
            return nodeIdList;
        };
        
        this.setNodeIdList = function(nodeidlist){  //为节点标识列表赋值
            if(nodeidlist instanceof Array){
                nodeIdList = nodeidlist;
                index = 0;  //每次赋值，都把index重新设置为0
            }
        };
    
        this.hasNextNode = function(){  //是否存在满足搜索条件的下一节点
          if(nodeIdList == null || index+1 >=nodeIdList.length){
              return false;
          }else{
              return true;
          }
        };
        
        this.getNextNodePath = function(){  //返回满足搜索条件的下一个节点的路径
            if(this.hasNextNode()){
                index++;
                return nodeIdList[index];
            }
        };
    };//end SearchResult主类

    
